From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 25D1C3858D37 for ; Tue, 1 Nov 2022 09:40:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 25D1C3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102d.google.com with SMTP id h14so12673499pjv.4 for ; Tue, 01 Nov 2022 02:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=ckp0NyGR5FaQ+uHd6TIs16uMo55hpAczc2gWdXfYLh8=; b=ADfkCqwq/xDshUUOTgWiD2S4IvMF9SjsV+YvJnPrezTJvuNy10SlQALFGpsqr/6VAY D8+tWnWxBPS3KCvewJ1uZn/6PCuo85Re5zYPIPqKpGJyVAO+8I9aTGeXSMgPrRWOK88M X8+uiygJ+ZFf3yKTlYM7Ok9cW/4kgVZkXPImuHMYPag7f8MDR1N/gytBoYMq5wlynPeD 3qxu0IOysLz5/PYgSpzfbh9VWpLXHD1ZEaoOjsLF9T6Ws0Uf+B0TCNQUHyllzL6RKV0M H/AlBmCbEK0Xn5AZB4D9iBJ9TAfeBg7ahXCarNZpoj+Aroh8fblHtxggGnP8YK5OHALp eEew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ckp0NyGR5FaQ+uHd6TIs16uMo55hpAczc2gWdXfYLh8=; b=dKArsSvEWvD85e4zazuRb/lPnJK/3FiDZMVdCgCmi7oUzptQeL4bkkWykYSs7Pafb2 ayWIpcobftIX6KWpoAIDoKk3w7qdGBnKiOLMax2TLthGzZiKAOSn0hMI6fF0lHjMInIm 5jKk/bS3RK2np6Uyer8VwdKhpncIvivdlNX+3QYAYgy+T7mWCifqtX1jBHvE/FgEeyB9 FRXM4UYxJAN2N/Z2uHvFj5HwwgH1aDThUINsR4HTwilQZ58Tf6k5kYi/XO+WuD0umfpL X23JVrWKJn79i9GRCA7RV3BIHE5ibUaxmwJ0QyVbAUXkGiYTeF2/aAN1hsNGAojslIMs sqQg== X-Gm-Message-State: ACrzQf1XE1M1yNWTuZK+F7jCGGab45bYccKM1zsgdgLffLj2vABB8lHE y4L7LBVKxzS0w5BYMrsrsgHAkshch+Y= X-Google-Smtp-Source: AMsMyM4QHIsepcOahemxn0eUxz/VUodQHkR/5h+3lqo/KwHuhDWdQAvgGpZIKeuFL1YQ9E8KaJWk9w== X-Received: by 2002:a17:902:6906:b0:186:d8d7:1d1e with SMTP id j6-20020a170902690600b00186d8d71d1emr18358642plk.30.1667295626042; Tue, 01 Nov 2022 02:40:26 -0700 (PDT) Received: from [192.168.5.149] ([111.202.46.254]) by smtp.gmail.com with ESMTPSA id b7-20020aa78ec7000000b00561382a5a25sm6064284pfr.26.2022.11.01.02.40.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Nov 2022 02:40:25 -0700 (PDT) Message-ID: Date: Tue, 1 Nov 2022 17:40:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Content-Language: en-US To: gdb@sourceware.org From: Iru Cai Subject: GDB cannot step or break into template functions compiled with g++ -Og Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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 (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) Breakpoint 1 at 0x1151: file test.cpp, line 2. (gdb) r Starting program: /tmp/test Breakpoint 1, t0 (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) 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(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(n=5) at test.cpp:4:6    1       template    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