[lldb-dev] how to set a watchpoint on an "unsigned short" parameter ?

Jason Vas Dias via lldb-dev lldb-dev at lists.llvm.org
Thu Feb 14 11:28:07 PST 2019


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


More information about the lldb-dev mailing list