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.

2
  • 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. Commented Apr 4, 2017 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). Commented Apr 5, 2017 at 23:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.