开发者

How do debuggers get line numbers of commands?

开发者 https://www.devze.com 2023-02-09 07:46 出处:网络
I\'m trying to get line numbers of address I collected in a stackwalk by using symgetlinefromaddr64, but I can\'t seem to get addresses of simple commands or their lines.

I'm trying to get line numbers of address I collected in a stackwalk by using symgetlinefromaddr64, but I can't seem to get addresses of simple commands or their lines.

for example, if i'm looking at the method:

void Test(int g)
{
  g++;
  DoSomething(g);
  g--;
}

I'll get only th开发者_开发技巧e line number of "DoSomething", but I want the line numbers of "g++" etc. I suppose it is doable because debuggers do it. how can I do it myself in c++ on windows?


A stack walk will only retrieve addresses that are stored on the stack, which pretty much means function calls. If you want the address of your g++ or g--, you'll need to use something other than a stack walk to get them (e.g., SymGetFileLineOffsets64). If you're starting from a stackwalk and have info from SymGetLineFromAddr64, you can use SymGetLineNext64 and SymGetLinePrev64 to get information about the surrounding lines.


The only way to do it is to use compiler generated symbol files like the *.pdb files for microsoft visual studio compilers (pdb stands for program database). These files contain all symbols used during the compilation step. Even for a release compilation you'll get information about the symbols in use (some may have be optimized away).

The main disadvantage is that this is highly compiler dependent/specific. gcc for example may include symbol information in the executable so-file or executable. Other compilers have other formats...

What compiler do you use (name/version)?

0

精彩评论

暂无评论...
验证码 换一张
取 消