How to view the disassembly in Code::Blocks?
Asked Answered
S

2

8

I read this article about some low level underpinnings of C/C++, and the author is basically showing us through the assembly code generated by the compiler, line by line. He is using VS 2010, but I don't, I use Code::Blocks. How do I view the disassembly there? When I go to debugger, and click disassembly, it shows me a blank window...

This is the C++ (.cpp) code (the whole code) I compiled:

int main()
{
    int x = 1;
    int y = 2;
    int z = 0;

    z = x + y;

    return 0;
}
Score answered 8/3, 2012 at 14:28 Comment(2)
If you are just interested in assembly and not Code Blocks in particular you can use gcc -S and it'll generate an assembly file on the lines of *.s, *.asmNaranjo
Cool, I'll boot Linux and do that. But I'd like to know how to do this.Score
N
10

The kind of disassembly that the author shows in the article is called inter-leaved disassembly ( C and disassembly interleaved ) which a few IDEs like Visual Studio support. Code Blocks does not support. But Code Blocks has a separate disassembly window like this

Diassembly Window

Select a source line. Right Click. Say Run to Cursor. Now Debug->Debugging Windows->Disassembly. Instead of Run to cursor you can also set break points and then do this. But somehow it wasn't going well with mine, so I am suggesting Run to Cursor method.

Hope it helps.

Naranjo answered 8/3, 2012 at 15:44 Comment(8)
OK. Lets sync up from the beginning. I dwlded Code Blocks from here- sourceforge.net/projects/codeblocks/files/Binaries/10.05/… File->New->Project->Console Application->C++->Enter Project Title->GNU GCC Compiler->Finish Now, Build->Build. Now place the cursor @ line 7 in main.cpp. Right Click and say Run to Cursor. Now a pop up window asks whether you wanna save perspective. Say no! Now, do as explained in the answerNaranjo
@Bane Any luck with my latest comment?Naranjo
Sorry for the wait, but I have been occupied by something else. I did what you said, I can now see the Run to cursor command. When I execute it, something starts happening, a console window pops up for a moment, but there is no window that asks me something about the perspective. After that, I opened up the disassembly, and this is what I saw: img651.imageshack.us/img651/1395/tse.png. I didn't download the same version as you did, but I think that things like this shouldn't be different. I am downloading the new version now to make sure, though.Score
"Installer integrity check has failed", an error of that kind appears. I think I have the newest Code::Blocks version, and I doubt that they would change such a feature...Score
Are the breakpoints hitting? When the breakpoint hits, Disassembly window should automatically be populatedNaranjo
Seems like they aren't. I've put a breakpoint (that little red dot) at line 7, I compile it, then run it, all the while having the disassembly window opened, but "nothing" happens. It just compiles and runs, doesn't indicate anything else...Score
I think you are running it and not debugging it. After setting the breakpoint ( Just say toggle breakpoint on any line, a new BP will come up ) Now select Debug->Start ( F8 shortcut ) NOT Build->Run. Now BPs will surely hit and you will see disassembly populatedNaranjo
Aha! It works now. I am at my school now, and I remember that at home, I couldn't start the debugger. Probably because some of the settings. Thanks!Score
B
4

This is a new answer to an old post. The other answer is completely on topic, but makes one outdated statement: "Code Blocks does not support_",... inter-leaved disassembly ( C and disassembly interleaved ).

This is no longer true. Newer versions of Code::Blocks have updated that feature.

Using Code::Blocks version 17.12 with gcc (tdm-1) version 5.1.0 and the OP code

And following the instructions:

  • In the Code::Blocks editor, right-click on the line of interest in the source file, and from the resulting context menu select Run to cursor. For this illustration the closing bracket } for the main function was right clicked.

  • Then, from title bar menu select Debug->Debugging Windows->Disassembly. This results in a popup showing assembly interleaved with source code:

  • This results in the following image clearly showing that the C source and assembly code are interleaved:

enter image description here

Banna answered 22/7, 2020 at 14:57 Comment(2)
Zombie, Zombie :)Excreta
youtube.com/watch?v=6Ejga4kJUts - resuurection of an old thread reminded me of this song.Excreta

© 2022 - 2024 — McMap. All rights reserved.