This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: compile: objfiles lifetime UI


On Thu, 07 May 2015 04:53:37 +0200, Alexandre Oliva wrote:
> However, it's not clear where to draw the line when a (pointer to a)
> string (literal) is passed to some inferior function.  Technically, it
> is an escaping pointer, but printf won't save it, whereas add_to_list
> will.  So we don't want it to be an error, at most a warning.

OK, you are right that printf() would be the most common false positive.
printf() could be excepted but that is not much foolproof solution.


> But then, wouldn't we be better served by teaching users to use strdup
> in gdb-compile snippets when they wish to get strings preserved (and
> permanently leaked) in the inferior?

If GDB wants to at least catch up with LLDB then no.  In LLDB it just works.
And personally I do not think "teaching users" works anymore, if it does not
work out of the box the user will just use a better tool.

------------------------------------------------------------------------------
The most simple case in LLDB just works:
   1   	#include <stdio.h>
   2   	char *a;
   3   	int main(void) {
-> 4   	  puts(a);
   5   	return 0; }
(lldb) p a="foo"
(char *) $0 = 0x00007ffff7ff5000 "foo"
(lldb) c
Process 13050 resuming
foo
Process 13050 exited with status = 0 (0x00000000) 
------------------------------------------------------------------------------

This is because LLDB always keeps the last 'injected code' mapped.  But it is
only the last 'injected code' so a more complicated case no longer works:

------------------------------------------------------------------------------
   1   	#include <stdio.h>
   2   	char *a,*b;
   3   	int main(void) {
-> 4   	  puts(a); puts(b);
   5   	return 0; }
(lldb) p a="foo"
(char *) $0 = 0x00007ffff7ff5000 "foo"
(lldb) p b="bar"
(char *) $1 = 0x00007ffff7ff5000 "bar"
(lldb) c
Process 13135 resuming
bar
bar
Process 13135 exited with status = 0 (0x00000000) 
------------------------------------------------------------------------------

For that case one already needs to read 'help print' where LLDB has:
    User defined variables:
	You can define your own variables for convenience or to be used in
	subsequent expressions.  You define them the same way you would define
	variables in C.  If the first character of your user defined variable
	is a $, then the variable's value will be available in future
	expressions, otherwise it will just be available in the current
	expression.

So in LLDB one can do:

------------------------------------------------------------------------------
   1   	#include <stdio.h>
   2   	char *a,*b;
   3   	int main(void) {
-> 4   	  puts(a); puts(b);
   5   	return 0; }
(lldb) p char $a[]="foo";a=$a
(char *) $0 = 0x00007ffff7ff5030 "foo"
(lldb) p char $b[]="bar";b=$b
(char *) $1 = 0x00007ffff7ff5040 "bar"
(lldb) c
Process 13260 resuming
foo
bar
Process 13260 exited with status = 0 (0x00000000) 
------------------------------------------------------------------------------

Originally I wanted to make it even more automatic than the LLDB's $-variables
but that looks as not really possible by that IR analysis. So personally
I think GDB/GCC should do the same as LLDB so that the users are not forked
from how they are already used to LLDB.

Technically GCC could put the $ variables into some new section?


Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]