[lldb-dev] how to set a watchpoint on an "unsigned short" parameter ?
Jason Vas Dias via lldb-dev
lldb-dev at lists.llvm.org
Fri Feb 15 08:33:15 PST 2019
Good day Ted -
Thanks for responding - but I did try that one:
(lldb) wa s v x
error: Watchpoint creation failed (addr=0xffffffffffffffff,
size=0, variable
expression='x').
error: cannot set a watchpoint with watch_size of 0
(lldb) wa s -s 2 v x
invalid command 'watchpoint set -s'.
(lldb) wa s v -s 2 x
error: Watchpoint creation failed (addr=0xffffffffffffffff,
size=0, variable
expression='x').
error: cannot set a watchpoint with watch_size of 0
I can't seem to get lldb to recognize the '-s' / '--size' options no matter
where I put them . And the documentation, such as it is,
(on https://lldb.llvm.org/lldb-gdb.html), is very vague and incomplete.
I guess my problems are because I am compiling with GCC , and trying
to debug with LLDB .
But since the program I am debugging is targetted mainly for the
Linux platform,
(I am just using MacOSX for testing) I wanted to compile with GCC .
I guess it is not possible to debug GCC compiled programs with LLDB ?
The problem I am trying to track down is stack corruption caused by
fprintf() :
void f ( void *r, unsigned short x )
{ ...
fprintf(stderr, "some string %lu %c\n",
r==(void*)0UL)? 255UL : A_MACRO(r),
x? '0' : '1'
);
// after this fprintf, the value of x changes from 12 to 8630 .
// why ? It would be nice to be able to use LLDB to find out,
// but this does not work.
}
I've just had to comment out the fprintf , so the problem does not occur.
Coming from a background of using GDB for the past 25 years, I find
this lack of watchpoint support in LLDB very difficult to accept.
Thanks & Best Regards,
Jason
On 15/02/2019, Ted Woodward <tedwood at quicinc.com> wrote:
> "w s v x" would be the command you want.
>
>
> (lldb) b f
> Breakpoint 1: where = watch`f + 12 at watch.c:5:4, address = 0x000050ec
> (lldb) r
> hexagon-sim INFO: The rev_id used in the simulation is 0x00004060
> (v60a_512)
> hexagon-sim INFO: Setting up debug server on port 57824
> Process 1 launched: '/usr2/tedwood/lldb_test/watch' (hexagon)
> Process 1 stopped
> * thread #1, name = 'T1', stop reason = breakpoint 1.1
> frame #0: 0x000050ec watch`f(i=2) at watch.c:5:4
> 2
> 3 unsigned short f(unsigned short i)
> 4 {
> -> 5 i++;
> 6 return i;
> 7 }
> 8
> (lldb) w s v i
> Watchpoint created: Watchpoint 1: addr = 0x0410eec6 size = 2 state = enabled
> type = w
> declare @ '/usr2/tedwood/lldb_test/watch.c:3'
> watchpoint spec = 'i'
> new value: 2
> (lldb) c
> Process 1 resuming
>
> Watchpoint 1 hit:
> old value: 2
> new value: 3
> Process 1 stopped
> * thread #1, name = 'T1', stop reason = watchpoint 1
> frame #0: 0x000050f8 watch`f(i=3) at watch.c:6:10
> 3 unsigned short f(unsigned short i)
> 4 {
> 5 i++;
> -> 6 return i;
> 7 }
> 8
> 9 int main(int argc, char **argv)
>
>
>
> -----Original Message-----
> From: lldb-dev <lldb-dev-bounces at lists.llvm.org> On Behalf Of Jason Vas Dias
> via lldb-dev
> Sent: Thursday, February 14, 2019 1:28 PM
> To: lldb-dev at lists.llvm.org
> Subject: [lldb-dev] how to set a watchpoint on an "unsigned short" parameter
> ?
>
> Good day -
>
> I'd be most grateful if anyone could enlighten me as to how
> to set a watchpoint on an unsigned short parameter variable
> in lldb .
>
> I am trying to follow the instructions at :
> https://lldb.llvm.org/lldb-gdb.html
> but they do not work to set watchpoints.
>
> There seems to be no other documentation for LLDB commands -
> or if anyone knows of any , please let me know.
>
> I have a function like :
> void f ( unsigned short x )
> { .... }
>
> With the debugger stopped inside f, I have tried:
>
> (lldb) p &x
> (uint16_t *) $3 = 0x00000001001122c0
> (lldb) wa s v -s 2 -w write 0x00000001001122c0
> error: no variable named '0x00000001001122c0' found in this frame
> (lldb) wa s v -s 2 -w write x
> error: Watchpoint creation failed (addr=0xffffffffffffffff, size=0,
> variable
> expression='x').
> error: cannot set a watchpoint with watch_size of 0
> (lldb) wa s e -s 2 -w write 0x00000001001122c0
> error: expression evaluation of address to watch failed
> expression evaluated: -s 2 -w write 0x00000001001122c0
> (lldb) wa s e -s 2 -w write *0x00000001001122c0
> error: expression evaluation of address to watch failed
> expression evaluated: -s 2 -w write *0x00000001001122c0
> (lldb) wa s e -s 2 -w write ((unsigned short*)0x00000001001122c0)
> error: expression evaluation of address to watch failed
> expression evaluated: -s 2 -w write ((unsigned
> short*)0x00000001001122c0)
> (lldb) wa s v -s 2 -w write &x
> error: 'x' doesn't have a valid address
> # ^- this error is really strange, particularly as I can do:
> (lldb) p &x
> (uint16_t *) $5 = 0x00000001001122c0
>
> It seems to me lldb's implementation of watch points is fundamentally
> broken -
> there is no way I've been able to get it to work .
>
> Unfortunately, I have to use MacOSX, so gdb is not available.
>
> Please, can anyone suggest how to successfully set a watchpoint on
> a parameter (stack) located variable value with lldb ?
> It does not seem to be possible.
>
> My next step, if no answers to this mail, would be to analyse the LLDB
> source code to see if I can figure out how watchpoints are meant to
> be set, seeing as there is no reference documentation for LLDB commands,
> either installed as manual pages or online. This to me makes LLDB
> unsuitable
> for production use, but unforunately I have to use it (I need to debug
> under
> MacOSX 10,14.3 ).
>
> The help output for is of no use either:
> (lldb) help watch set
> "Syntax: watchpoint set <subcommand> [<subcommand-options>]
> The following subcommands are supported:
> expression -- Set a watchpoint on an address by supplying an
> expression. Use the
> '-w' option to specify the type of watchpoint and the '-s'
> option to specify the
> byte size to watch for.
> "
> The above statement is provably false:
> (lldb) wa s v -s 2 x
> error: Watchpoint creation failed (addr=0xffffffffffffffff, size=0,
> variable expression='x').
> error: cannot set a watchpoint with watch_size of 0
> # maybe the -s option goes after the 'set' ? no:
> (lldb) wa s -s 2 v reader_id
> invalid command 'watchpoint set -s'.
>
> All attempts to
> "Use the '-w' option to specify the type of watchpoint and the '-s'
> option to
> specify the byte size to watch for.
> "
> fail, so there must be alot missing from the help description.
>
> The help for the variable syntax is also vague, and provably false :
> "variable -- Set a watchpoint on a variable. Use the '-w'
> option to specify the type
> of watchpoint and the '-s' option to specify the byte
> size to watch for.
> If no '-w' option is specified, it defaults to write. If
> no '-s' option is
> specified, it defaults to the variable's byte size. Note
> that there are
> limited hardware resources for watchpoints. If
> watchpoint setting
> fails, consider disable/delete existing ones to free up
> resources.
>
> (lldb) wa s v x
> error: Watchpoint creation failed (addr=0xffffffffffffffff, size=0,
> variable
> expression='x').
> error: cannot set a watchpoint with watch_size of 0
> (lldb) wa s -s 2 v x
> invalid command 'watchpoint set -s'.
> (lldb) wa s v -s 2 x
> error: Watchpoint creation failed (addr=0xffffffffffffffff, size=0,
> variable
> expression='x').
> error: cannot set a watchpoint with watch_size of 0
>
> So lldb's watch command can neither get the size from a '-s' option, nor
> can
> it get the size from sizeof(variable) . How then is one meant to set the
> size ?
>
> Obviously, lldb's watchpoint implementation needs much further work -
> has
> anyone been able to get it to do anything useful ? If so, please let me
> know how,
> and what.
>
> If there is any reference documentation for lldb, besides the false and
> misleading
> 'https://lldb.llvm.org/lldb-gdb.html', which actually describes in detail
> and
> correctly the syntax of every lldb command, please let me know.
>
> Any ideas gratefully received.
>
> Thank You & Best Regards,
> Jason Vas Dias
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
>
More information about the lldb-dev
mailing list