0

I'm using Xcode/lldb to debug some C code. But I get this error

(lldb) p (int)g_list_position(start, next)
(int) $0 = 1
(lldb) p (int)g_list_position(start, this)
error: expected unqualified-id
error: invalid use of 'this' outside of a non-static member function

So apparently lldb things "this" is a reference to a class, in spite of it being a perfectly valid var in C (and its value is 0, as it should be). Is there some way to escape this name in lldb?

Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98

1 Answers1

1

No, the expression evaluator in lldb wraps your expression (at at a source level) with some C++ to pass the arguments in. The only suggestion I can think of is to get the address in the this pointer and put that in the expression explicitly. It's a goal of the expression evaluation that you can copy a line of source in your program and execute it as an expression in lldb .. but this is a corner case where that does not work - variables in C that are reserved words in C++.

Jason Molenda
  • 14,835
  • 1
  • 59
  • 61
  • Interesting... ok it's not a big deal, but I figured I'd ask. Ironically, in the pane to the left where it lists the variables I can see it understand "this" just fine. – Maury Markowitz Dec 08 '19 at 15:48
  • Yah, that doesn't go through the expression evaluation (it doesn't go through the compiler), that's a simple variable lookup. I suspect `p this` will fail. `v this` (aka `frame variable this`) will succeed because frame variable is doing a simple search for variables with that name in the current scope. It's the same mechanism that Xcode uses to populate the Locals window. – Jason Molenda Dec 08 '19 at 20:47