User forums > General (but related to Code::Blocks)
GCC 4.4.0-tdm-1 for MinGW (with installer)
ollydbg:
Thanks!
I have Googled a lot. But too confusing
1.Someone said when "-g" is enabled, a inline function will treated as a normal function.
2,I use "nm" tool to exam the symbol table in the exe file, there is a 0x4XXXXX address of an inline function :D
Edit
Here is another test:
If the inline function be referenced in two CPP file, like (main.cpp and a.cpp), then, this will reproduce the bug.
But if the inline function was only called in single cpp file, ( for example, only main.cpp call this inline function), then, I can successfully set breakpoint in the header :D
Ceniza:
A personal God (actually a guy who works for nvidia (I guess he still works there)) once told me a way to guarantee the compiler generates the function code for that case (inline) is to query the address of the function (and use it, I think... (it was a long time ago)). However, since the code is still... inlined... everywhere else it is called, setting a breakpoint there is not likely to work, unless you call it through a function pointer (I haven't tried it myself, though).
Why don't you try with "-fno-inline"?
<edit>
Every "translation unit" (roughly each cpp file with all the included headers) that uses an inline function should get a copy of it in case it is not inlined. It would be something similar to static functions.
</edit>
ollydbg:
--- Quote from: Ceniza on June 25, 2009, 08:03:46 am ---Why don't you try with "-fno-inline"?
--- End quote ---
Thanks for your help. I tested it, but this options has no effect :(.
Edit
function f1() has address
--- Quote ---> p f1
$1 = {void (void)} 0x41894c <f1()>
--- End quote ---
So, the 0xd value is quite strange :shock:
Edit2
nm -s
result:
--- Quote ---00418818 t .text
0040d7a8 t .text
004141b8 t .text
0041894c t .text$_Z2f1v
00418968 t .text$_ZN9__gnu_cxx13__scoped_lockD1Ev
00418a1c t .text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEE2fdEv
00418a2c t .text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEE4fileEv
--- End quote ---
thomas:
__attribute__ ((used)) is the canonical way of forcing gcc to emit a function body whether all calls are inlined or not. However, this is mostly useful for libraries or for cases where the compiler cannot possibly know that you call a function (out of inline assembly, for example). It's of little use for your debugging problem, as the function is never called, like in Ceniza's proposal.
Try __attribute__ ((noinline)), which prevents the compiler from inlining a particular function. This, however, only disables inlining, you may still face problems due to CSE and other optimisations which dead-strip function calls that have no effect.
If you want to prevent those too, use said attribute and add asm(""); in the function body. Due to the asm statement, the compiler cannot prove that no side effects take place, so it can't eleminate the function call.
EDIT:
Would have been good if I had looked at your code snippet too before answering. Class member declar-finitions as in your example are problematic. Why? Because the standard says (7.1.2.3) that these are inline, so it may be that the compiler still inlines those even if you tell it not to, as it's required by the language. Not sure what it does exactly, have to try.
ollydbg:
--- Quote from: thomas on June 25, 2009, 03:08:57 pm ---__attribute__ ((used)) is the canonical way of forcing gcc to emit a function body whether all calls are inlined or not. However, this is mostly useful for libraries or for cases where the compiler cannot possibly know that you call a function (out of inline assembly, for example). It's of little use for your debugging problem, as the function is never called, like in Ceniza's proposal.
Try __attribute__ ((noinline)), which prevents the compiler from inlining a particular function. This, however, only disables inlining, you may still face problems due to CSE and other optimisations which dead-strip function calls that have no effect.
If you want to prevent those too, use said attribute and add asm(""); in the function body. Due to the asm statement, the compiler cannot prove that no side effects take place, so it can't eleminate the function call.
EDIT:
Would have been good if I had looked at your code snippet too before answering. Class member declar-finitions as in your example are problematic. Why? Because the standard says (7.1.2.3) that these are inline, so it may be that the compiler still inlines those even if you tell it not to, as it's required by the language. Not sure what it does exactly, have to try.
--- End quote ---
Thank you for your help. I have tried these code below, but still has the same debug problem :(
a.h
--- Code: ---
__attribute__ ((noinline)) inline void f1(){
int a=7;
a=a+1;
a=5;
asm("");
};
--- End code ---
By the way, I have tried another "Class member declar-finitions" examples.
main.cpp
--- Code: ---#include <iostream>
using namespace std;
#include "a.h"
int main()
{
TestClass a;
a.func_inline();
return 0;
}
--- End code ---
a.cpp
--- Code: ---#include "a.h"
void f2(){
TestClass b;
b.func_inline();
}
--- End code ---
a.h
--- Code: ---class TestClass{
public:
void func_inline(){
int a;
a = 0;
a++;
}
};
--- End code ---
And still I can't set breakpoint in "func_inline" function body. see below:
--- Code: ---> break "C:/test/inline_2/main.cpp:12"
Breakpoint 2 at 0x401346: file C:\test\inline_2\main.cpp, line 12.
>>>>>>cb_gdb:
> break "C:/test/inline_2/a.h:7"
Breakpoint 3 at 0x6: file C:/test/inline_2/a.h, line 7. (2 locations)
>>>>>>cb_gdb:
> break "C:/test/inline_2/main.cpp:19"
No line 19 in file "C:\test\inline_2\main.cpp".
>>>>>>cb_gdb:
> run
Warning:
Cannot insert breakpoint 3.
Error accessing memory address 0x6: Input/output error.
--- End code ---
Seems I can't find any way to solve this. :(
By the way , If I totally comment the code in
--- Code: ---void f2(){
//TestClass b;
//b.func_inline();
}
--- End code ---
then, breakpoint can be set successfully in header file. This is the same as my previous example, if an inline function be called only once, we can set breakpoints in function body. :D
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version