1

How can one access the values like these using the Python from gdb?:

some_array_smartptr->operator[](0)->item // no errors are checked for sake of clarity

In gdb this line works fine, but I cannot figure out how to use it in Python as I am implementing the automated testing.

Please note, that both vector and smartptr are not standard, but are manually written. Semantics is the same though.

avp
  • 4,895
  • 4
  • 28
  • 40
  • Can you provide some more context around how you're accessing your program? I'm looking at this via the Review Queue and not a C++ developer, so I'm not able to answer, but it looks like there's room for improved clarity here. – Moshe Apr 04 '17 at 21:19
  • Currently my tests look like Python code which contains a list of strings line `"variable_x == value"` which elements execute one by one adding `if gdb.parse_and_eval(item)` and `then` clauses. I basically don't need any python code, it is kind of a wrapper for gdb lines and I'd like to simplify it. In fact, I use gdb lines just because the Python syntax to access the values is not clear and I'd like to clarify it (as I stated in the first sentence of the question). – avp Apr 05 '17 at 23:09

1 Answers1

1

The gdb.parse_and_eval() should do exactly what you want for live-process debugging.

Documentation.

I'd like to iterate through some arrays an so on.

The parse_and_eval returns a gdb.Value. Once you have that value, you can use any of the Values methods for further access.

Example.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Yes, this is what I currently do. The thing is, I'd like to iterate through some arrays an so on. In case of parse_and_eval() this looks really as wrong approach. Am I missing something? – avp Apr 05 '17 at 08:31