P
Peng Yu
Hi,
It is benifitical to use macro in certain cases.
http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html
However, I found that it is not easy to debug a macro. For example,
for the following program, I can not trace into the last macro in gdb.
In this sense, if I want to debug the code easily, should I avoid
using macros. Are there any better way to debug macros?
Thanks,
Peng
$ cat main.cc
#include <boost/typeof/typeof.hpp>
#include <iostream>
#define MACRO_DEF \
class A { \
public: \
A(int a) : _a(a) { } \
int the_a() const { return _a; } \
private: \
int _a; \
};
MACRO_DEF
#define MACRO \
A a(1);\
std::cout << a.the_a() << std::endl;
int main() {
MACRO
}
$gdb main-g.exe
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "x86_64-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".
(gdb) start
Breakpoint 1 at 0x40081c: file main.cc, line 20.
main () at main.cc:20
20 MACRO
(gdb) s
A (this=0x7fffb8f0de80, a=1) at main.cc:13
13 MACRO_DEF
(gdb) s
A::the_a (this=0x7fffb8f0de80) at main.cc:13
13 MACRO_DEF
(gdb) s
1
main () at main.cc:21
21 }
(gdb) n
0x00002afcf215b4ca in __libc_start_main () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
(gdb)
It is benifitical to use macro in certain cases.
http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html
However, I found that it is not easy to debug a macro. For example,
for the following program, I can not trace into the last macro in gdb.
In this sense, if I want to debug the code easily, should I avoid
using macros. Are there any better way to debug macros?
Thanks,
Peng
$ cat main.cc
#include <boost/typeof/typeof.hpp>
#include <iostream>
#define MACRO_DEF \
class A { \
public: \
A(int a) : _a(a) { } \
int the_a() const { return _a; } \
private: \
int _a; \
};
MACRO_DEF
#define MACRO \
A a(1);\
std::cout << a.the_a() << std::endl;
int main() {
MACRO
}
$gdb main-g.exe
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "x86_64-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".
(gdb) start
Breakpoint 1 at 0x40081c: file main.cc, line 20.
main () at main.cc:20
20 MACRO
(gdb) s
A (this=0x7fffb8f0de80, a=1) at main.cc:13
13 MACRO_DEF
(gdb) s
A::the_a (this=0x7fffb8f0de80) at main.cc:13
13 MACRO_DEF
(gdb) s
1
main () at main.cc:21
21 }
(gdb) n
0x00002afcf215b4ca in __libc_start_main () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
(gdb)