From: Iru Cai <vimacs.hacks@gmail.com>
To: gdb@sourceware.org
Subject: GDB cannot step or break into template functions compiled with g++ -Og
Date: Tue, 1 Nov 2022 17:40:22 +0800 [thread overview]
Message-ID: <cf490e3d-411e-d7b7-335b-230782a82a27@gmail.com> (raw)
Hi,
Tested with GDB 12.1 and GDB in binutils-gdb git 1751ca43fda, I find
that GDB cannot step or break into C++ template functions compiled with
g++ -Og (GCC version 12.2.0), for example:
```
template <typename T = int>
int t0(int n)
{
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += i * i;
}
return sum;
}
int t1(int n)
{
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += i * i;
}
return sum;
}
int main()
{
int a = t0(5);
int b = t1(5);
return a + b;
}
```
compile with: g++ -g -Og -o test test.cpp
Debugging with GDB 12.1, I get:
```
(gdb) b t0
Breakpoint 1 at 0x1151: file test.cpp, line 2.
(gdb) b t1
Breakpoint 2 at 0x1119: file test.cpp, line 14.
(gdb) r
Starting program: /tmp/test
Breakpoint 1, t0<int> (n=n@entry=5) at test.cpp:2
2 int t0(int n)
(gdb) s
main () at test.cpp:23
23 int b = t1(5);
(gdb) c
Continuing.
Breakpoint 2, t1 (n=n@entry=5) at test.cpp:14
14 for (int i = 0; i < n; ++i) {
(gdb) n
15 sum += i * i;
```
With GDB git, it even cannot recognize the template function name unless
I use the full name:
```
(gdb) b t0
Function "t0" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b t0<int>(int)
Breakpoint 1 at 0x1151: file test.cpp, line 2.
(gdb) r
Starting program: /tmp/test
Breakpoint 1, t0<int> (n=n@entry=5) at test.cpp:2
2 int t0(int n)
(gdb) s
main () at test.cpp:23
23 int b = t1(5);
```
While LLDB 14.0.6 can step into this function:
```
(lldb) b t0
Breakpoint 1: where = test`int t0<int>(int) at test.cpp:5:11, address =
0x0000000000001151
(lldb) r
Process 82245 launched: '/tmp/test' (x86_64)
Process 82245 stopped
* thread #1, name = 'test', stop reason = breakpoint 1.1
frame #0: 0x0000555555555151 test`int t0<int>(n=5) at test.cpp:5:11
2 int t0(int n)
3 {
4 int sum = 0;
-> 5 for (int i = 0; i < n; ++i) {
6 sum += i * i;
7 }
8 return sum;
(lldb) n
Process 82245 stopped
* thread #1, name = 'test', stop reason = step over
frame #0: 0x0000555555555156 test`int t0<int>(n=5) at test.cpp:4:6
1 template <typename T = int>
2 int t0(int n)
3 {
-> 4 int sum = 0;
5 for (int i = 0; i < n; ++i) {
6 sum += i * i;
7 }
```
Can anyone help to fix this?
Thanks,
Iru
reply other threads:[~2022-11-01 9:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cf490e3d-411e-d7b7-335b-230782a82a27@gmail.com \
--to=vimacs.hacks@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).