Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Enhancement] {-tracing, for better code understanding

Open marsej opened this issue 3 years ago • 8 comments

In OllyDbg you can trace the execution path which creates a history/log of what points or commented lines the execution traveled through. A facility for something like that would help understanding large codebases from another party.

When during debug the execution enters a { scope in .bf or .cpp, show in trace log the current method name+previous line+line number and make it clickable so you can go to that line

Then could also have option to select all or some of those traced lines and add breakpoints to them.

marsej avatar Apr 02 '21 11:04 marsej

You can step through it from the main menu bar, but also use F10(Step over), F11(step into), shift-F11(step out), F9(breakpoint)

RogueMacro avatar Apr 02 '21 11:04 RogueMacro

This isn't about stepping but tracing(and then adding bp's), similar to in OllyDbg or perhaps I didn't understand what you meant.

marsej avatar Apr 02 '21 11:04 marsej

@marsej You mean Stack Trace? It's a window for that

RogueMacro avatar Apr 02 '21 14:04 RogueMacro

OllyDbg has Stack Trace, Run trace, Log windows which each do different things. With unknown code/difficult cases those other windows help.

For instance you could "animate over" code which then logs commented lines into log window. Further the line previous to every {-character could be shown in that log. I'm not suggesting to copy OllyDbg behavior exactly just pointing out there's other type of traces than stack trace.

marsej avatar Apr 02 '21 15:04 marsej

I had an idea for a workaround:

Use Find and Replace to replace every "{" with "{ CallerInfo(); "

Where CallerInfo is:


		public static void CallerInfo(String member = Compiler.CallerMemberName, String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum) 
		{
			Console.WriteLine("{} {}: {}",filePath,line,member);
		}

This creates a trace.

EDIT: Uh well actually I need this for a .cpp file! See below for how to do similar thing in C++

marsej avatar Apr 11 '21 12:04 marsej

It might not be exactly what you are looking for, but it's an interesting idea: https://www.beeflang.org/docs/language-guide/comptime/ See last example of LogAttribute

RogueMacro avatar Apr 11 '21 12:04 RogueMacro

I actually need it for .cpp (for finding code paths for buggy and non-buggy cases). I found this:

printf("%s\n", __func__);

That prints "main" when in main();

EDIT: even better:

printf("%d: %s\n", __LINE__, __FUNCSIG__);

prints "linenumber: int __cdecl main(void)"

marsej avatar Apr 11 '21 12:04 marsej

I got the manual tracing working: None of the other project configurations worked except for Release-x64 in the Beef.sln file (compiled then attached VS manually to BeefIDE.exe EDIT: Changing startup project to IDEHelper did work as well) but with that I am able to get output below by regex replacing

{[ \t]*

with 

{ OutputDebugStrF("%s %d: %s\\n", __FILE__, __LINE__, __FUNCSIG__);

in BfPrinter.cpp in this case.

C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 11: __cdecl Beefy::BfPrinter::BfPrinter(class Beefy::BfRootNode *,class Beefy::BfRootNode *,class Beefy::BfRootNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 1303: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfIdentifierNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 957: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfExpression *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 700: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 784: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 788: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 795: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 893: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 174: void __cdecl Beefy::BfPrinter::WriteSourceString(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 131: void __cdecl Beefy::BfPrinter::Write(class Beefy::BfAstNode *,int,int)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 11: __cdecl Beefy::BfPrinter::BfPrinter(class Beefy::BfRootNode *,class Beefy::BfRootNode *,class Beefy::BfRootNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 1303: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfIdentifierNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 957: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfExpression *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 700: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 784: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 788: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 795: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 893: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 174: void __cdecl Beefy::BfPrinter::WriteSourceString(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 131: void __cdecl Beefy::BfPrinter::Write(class Beefy::BfAstNode *,int,int)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 11: __cdecl Beefy::BfPrinter::BfPrinter(class Beefy::BfRootNode *,class Beefy::BfRootNode *,class Beefy::BfRootNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 1303: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfIdentifierNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 957: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfExpression *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 700: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 784: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 788: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 795: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 893: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 174: void __cdecl Beefy::BfPrinter::WriteSourceString(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 131: void __cdecl Beefy::BfPrinter::Write(class Beefy::BfAstNode *,int,int)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 11: __cdecl Beefy::BfPrinter::BfPrinter(class Beefy::BfRootNode *,class Beefy::BfRootNode *,class Beefy::BfRootNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 1303: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfIdentifierNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 957: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfExpression *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 700: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 784: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)
C:\beefsrc\IDEHelper\Compiler\BfPrinter.cpp 788: void __cdecl Beefy::BfPrinter::Visit(class Beefy::BfAstNode *)

marsej avatar Apr 11 '21 15:04 marsej