GDB: Attempt to dereference generic pointer

前端 未结 1 398
旧时难觅i
旧时难觅i 2021-02-01 05:23

How can I make GDB do extra dereferences in a printing function like x/s?

When I try explicit dereferences in x/ I get the error \"Attempt to d

1条回答
  •  走了就别回头了
    2021-02-01 05:52

    The solution is to cast the pointers before dereferencing them.

    For example, picking up where we left off above:

    (gdb) x/s **((char ***) (0xc + $ebp))
    0xbfffedc8:  "/var/tmp/SO-attempt-to-dereference-generic-pointer/example"
    (gdb) x/s *(*((char ***) (0xc + $ebp)) + 1)
    0xbfffee03:  "first"
    (gdb) x/s *(*((char ***) (0xc + $ebp)) + 2)
    0xbfffee09:  "second"
    

    Note that the stack address 0xc + $ebp is itself a pointer to the contents of that stack location, and so we need char *** and not char **.

    0 讨论(0)
提交回复
热议问题