public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28935] New: GDB very slow stepping through LLVM compiled by Clang
@ 2022-03-02 18:25 msebor at gmail dot com
  2022-03-02 20:54 ` [Bug c++/28935] " simark at simark dot ca
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: msebor at gmail dot com @ 2022-03-02 18:25 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28935

            Bug ID: 28935
           Summary: GDB very slow stepping through LLVM compiled by Clang
           Product: gdb
           Version: 11.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
  Target Milestone: ---

Stepping through C++ code compiled by Clang takes much longer than when the
code is compiled by GCC.  For example, when debugging LLVM, each step takes a
second or more.  This is with the stock GDB (11.1-5.fc35) on x86_64 running
Fedora 35.  That makes using GDB for interactive work impractical.  Using GCC
instead of Clang to compile LLVM is a viable workaround but it's not without
issues of its own.  LLDB doesn't have the same problem as GDB but because it's
not fully compatible with GDB it's not a great solution for those of us used to
GDB.

I'd like to try to help isolate and fix this problem.  Below is a test case
independent of LLVM that shows a small but measurable difference between these
two scenarios.  The output is the number of microseconds it takes the three
'next' GDB commands to step over the three C++ statements in A::f(), averaged
over 100 runs.  In GCC-compiled code the average is 5.2 microseconds, in
Clang-compiled code it's 5.5 microseconds.  If the difference grows with code
size and/or complexity it could explain the much bigger 1 second delay in LLVM.
 If this test case isn't representative of the problem can you suggest what
might be?

$ (cat t.C && g++ -ggdb -o a.gcc.out t.C && (n=0; while [ $n -lt 100 ]; do gdb
-batch -nx -ex "break A::f" -ex run -ex next -ex next -ex next -ex continue
./a.gcc.out >/dev/null; n=$((n+1)); done) 2>&1 | awk 'BEGIN { t = 0.0 } { t +=
$1 } END { print t / 100 }' )
#include <iostream>
#include <string>
#include <time.h>

struct A
{
  void f () const
    {
      std::string s = "Hello, ";
      s += "World!";
      std::cout << s << std::endl;
    }
};

A a;

int main ()
{
  struct timespec t0, t1;
  clock_gettime (CLOCK_MONOTONIC, &t0);

  a.f ();

  clock_gettime (CLOCK_MONOTONIC, &t1);
  double t = (t1.tv_sec - t0.tv_sec) * 1e3 + (t1.tv_nsec - t0.tv_nsec) / 1e3; 
  fprintf (stderr, "%f ms\n", t / 1e3);
}
5.19838

$ (clang++ -ggdb -o a.clang.out t.C && (n=0; while [ $n -lt 100 ]; do gdb
-batch -nx -ex "break A::f" -ex run -ex next -ex next -ex next -ex continue
./a.clang.out >/dev/null; n=$((n+1)); done) 2>&1 | awk 'BEGIN { n = 0.0 } { n
+= $1 } END { print n / 100 }' )
5.52529

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-16 13:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 18:25 [Bug c++/28935] New: GDB very slow stepping through LLVM compiled by Clang msebor at gmail dot com
2022-03-02 20:54 ` [Bug c++/28935] " simark at simark dot ca
2022-03-02 22:41 ` msebor at gmail dot com
2022-03-03  2:28 ` simark at simark dot ca
2022-03-03 18:37 ` ssbssa at sourceware dot org
2022-05-16 13:33 ` tromey at sourceware dot org

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).