2

Can't we traverse the array of structs ? I mean for each index by checking the content of structs and print each field accordingly? As we can do for a struct like

s = gdb.parse_and_eval(expr)
for k in s.type.keys():
    v = s[k]
    if is_pointer(v):
          .....
    elif is_array(v):
          .....

How to get access control on elements at each indices of an array?

Baijnath Jaiswal
  • 377
  • 5
  • 17

1 Answers1

4

You can index an array using the [] notation. Like, if 'v' is a gdb.Value representing an array or a pointer, you can fetch the 5th element with v[5].

The manual has a long section on the Value API that explains all of this.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • One more doubt i have, while doing `gdb.execute('thread apply all bt')` at particular thread it is showing `Cannot access memory at address 0x5effffe500` and getting quit from gdb prompt. if i use `try:` `gdb.execute('thread apply all bt')` `except gdb.error:` `gdb.write(',\n')` then it is not quiting from gdb prompt but it is skipping all further threads. I want to go in each thread and print `bt` for all threads one by one. Is there any solotion to this or any other way to get this..? Kindly guide.. – Baijnath Jaiswal Jun 20 '13 at 09:25
  • Iterate over the threads in Python instead. You can also compute stack traces from Python. – Tom Tromey Jun 20 '13 at 13:08
  • Thanks tromey:-) now i am able to iterate over all threads and printing backtrace of each thread but when exception occurs, i want to print the exact gdb error message like `Cannot access memory at address 0x5effffe500` with right address in my exception handler. So how to get gdb error message? – Baijnath Jaiswal Jun 21 '13 at 05:57
  • It is in the python exception. You really ought to read through the python api part of the manual. – Tom Tromey Jun 21 '13 at 13:56
  • Sure tromey, I will read again. One more thing, It seems there is No any constant defined for Array of Pointers (e.g. gdb.TYPE_CODE_PTR) in gdb module..? I went through manual but did not found :( – Baijnath Jaiswal Jun 23 '13 at 15:31
  • There's an array type, and you can look at the array's element type to determine if it is an array of pointers. – Tom Tromey Jun 23 '13 at 20:04
  • 3
    Where is this mythical manual? The only one I can find (at https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior) doesn't say anything about arrays. – Chris Dodd Apr 13 '17 at 22:36
  • 3
    Yeah, funny, I see that the array syntax isn't documented. That's a bug in the gdb manual. – Tom Tromey Apr 14 '17 at 02:19