John Smith
2015-Jan-04 15:02 UTC
[LLVMdev] Writing my own debugger... use __builtin_frame_address or is there something better?
Hi LLVM list, Thanks for having me here. I'm writing my own debugger for my (secret) language... I don't know anything about LLVM beyond the general "big picture"... I haven't any real practical experience working with it... beyond just using XCode... So... really the problem is... I'm generating some functions... by "compiling to C"... so my compiler just writes a plain ".cpp" text file. I've tried debugging the output in Xcode but it's a horrible experience. It's like a C++ developer having to stepping through ASM instead of C... So I thought "it won't be too hard to make my own debugger"... "all I need is the ability to get the current variables off the current function... and probably the variables from the calling functions... as long as I can do THAT... I can do the rest myself". Something like this: int Func(Type1* self, Type2* P) { DB_GetStackPointer(1); // "DB_" means its a function for debugging the code // So we save the current stack pointer to a global variable // and tell the debugger that we are on line 1 of the current file's source code. int N = 0; DB_Line(2); // Tell the debugger that we have advanced to line 2 of our source code. Type2* Curr = GetFirst(P); DB_Line(3); while (Curr) { DB_Line(4); Type3* Tmp = SubFunc(Curr, self, nil); if (!Tmp) { PrintError("Error"); return 0; } DB_Line(5); N++; DB_Line(6); Item = GetNext(Curr); DB_Line(7); }; DB_Line(8); return N + 1; } All I need to do then... is implement DB_Line and DB_GetStackPointer. The idea is that DB_GetStackPointer will save the current stack pointer... and DB_Line will go to a func that lets me read the current variables off that stack pointer, and then send them via a socket/TCP-connection... to my debugger. However... I've fooled around with __builtin_frame_address and... I can't figure out how to properly use it. int* FA1 = (int*)__builtin_frame_address(1); int P0_ = FA1[0]; int P1_ = FA1[1]; int P2_ = FA1[2]; int P3_ = FA1[3]; Something like this... but NONE of these int variables contain the actual pointers stored in the calling function! I'm looking for the value "Type2* Value = 0x25b1160" But I just see values like this: P0_ int 0xbffff758 0xbffff758 P1_ int 0x00008ec3 0x00008ec3 P2_ int 0x004040f8 0x004040f8 P3_ int 0x00426638 0x00426638 Any ideas? Or is there some kind of inbuilt LLVM things to help me write my own debugger? Something better than __builtin_frame_address I don't mind relying on LLVM... It doesn't need to be used outside of LLVM...
Joerg Sonnenberger
2015-Jan-04 16:44 UTC
[LLVMdev] Writing my own debugger... use __builtin_frame_address or is there something better?
On Sun, Jan 04, 2015 at 03:02:30PM +0000, John Smith wrote:> "all I need is the ability to get the current variables off the current > function...Finding the functions on the stack is easy. Finding which auto variables are where is *much* harder. Joerg
Theodore H. Smith
2015-Jan-04 17:34 UTC
[LLVMdev] Writing my own debugger... use __builtin_frame_address or is there something better?
> On 4 Jan 2015, at 16:44, Joerg Sonnenberger <joerg at britannica.bec.de> wrote: > > On Sun, Jan 04, 2015 at 03:02:30PM +0000, John Smith wrote: >> "all I need is the ability to get the current variables off the current >> function... > > Finding the functions on the stack is easy. Finding which auto variables > are where is *much* harder.That explains why I couldn't find anything. I was hoping there might be an LLVM compiler switch to say "allocate these variables in a linear straightforward fashion"... If theres no such switch then... what is considered the "right approach with LLVM" to creating your own debugger? Or anything that helps with my original question.
John Smith
2015-Jan-04 17:39 UTC
[LLVMdev] Writing my own debugger... use __builtin_frame_address or is there something better?
> > On 4 Jan 2015, at 16:44, Joerg Sonnenberger <joerg at britannica.bec.de> wrote: > > On Sun, Jan 04, 2015 at 03:02:30PM +0000, John Smith wrote: >> "all I need is the ability to get the current variables off the current >> function... > > Finding the functions on the stack is easy. Finding which auto variables > are where is *much* harder.That explains why I couldn't find anything. I was hoping there might be an LLVM compiler switch to say "allocate these variables in a linear straightforward fashion"... If theres no such switch then... what is considered the "right approach with LLVM" to creating your own debugger? Or anything that helps with my original question.