[lldb-dev] analog of "gdb --args"

Jim Ingham jingham at apple.com
Thu Jan 20 13:49:12 PST 2011


Eh, looks like the help isn't quite right.  

The way it works is that all the arguments after the last recognized argument are treated as program arguments.  You don't need to provide a flag indicating this.  In terms of the general lldb command syntax these would just be considered the arguments to the "lldb" command...

So for instance:

$ lldb args foo bar baz 
Current executable set to 'args' (x86_64).
(lldb) source list -n main
File: /tmp/args.c.
   1   	int main (int argc, char ** argv)
   2   	{
   3   	  int i;
   4   	  for (i = 0; i < argc; i++)
   5   	    printf ("Arg[%d]: \"%s\"\n", i, argv[i]);
   6   	
   7   	  return 0;
   8   	}
(lldb) run
Process 27956 launched: '/private/tmp/args' (x86_64)
(lldb) Arg[0]: "/private/tmp/args"
Arg[1]: "foo"
Arg[2]: "bar"
Arg[3]: "baz"
(lldb) Process 27956 exited with status = 0 (0x00000000) 

There are two little tricks.  If you specify the file to be debugged with the -f argument, then the remaining arguments start at argv[1], otherwise they start at argv[0].  So the following is equivalent to the first command:

$ lldb -f args foo bar baz


And the lldb command syntax in general allows flags and arguments to be intermixed, so if want to pass flag-like arguments to your program, you have to terminate the actual flags with "--".  So:

$ lldb -- args -foo -bar -baz

would be correct.

Hope this helps,

Jim

On Jan 20, 2011, at 7:15 AM, Alexey Zakhlestin wrote:

> gdb has a nice option --args, which allows to specify additional parameters for executable like this:
> 
>    gdb --args /path/to/executable arg1 arg2 --param1
> 
> is there similar option for lldb?_______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev





More information about the lldb-dev mailing list