Article View: gnu.gdb.bug
Article #1262Re: gdb 6.1 blues
From: Nikos Balkanas
Date: Wed, 23 Mar 2005 03:17
Date: Wed, 23 Mar 2005 03:17
93 lines
5099 bytes
5099 bytes
Hi Eli, Thanks for your comments. I followed them and the debug output came out fine. One final observation: You only need to use the optimizer when you want to debug gcc (or its optimizer). But in that case, printfs are no better, since they change the flow of the optimized code. For straight code debugging, no optimizer flags should be used. Do not worry making gdb more compatible with the -g -O2 flag. I would never send a client a production application compiled with the -g flag, and only on rare occasions I would use the -O2 flag. Thanks, Nikos ----- Original Message ----- From: "Eli Zaretskii" <eliz@gnu.org> To: "Nikos Balkanas" <nbalk@hol.gr> Cc: <bug-gdb@gnu.org> Sent: Monday, March 21, 2005 7:39 AM Subject: Re: gdb 6.1 blues > > From: "Nikos Balkanas" <nbalk@hol.gr> > > Date: Mon, 21 Mar 2005 04:42:19 +0200 > > > > Problem: > > > > (1) Source lines get messed up > > (2) Just evaluated variables, are "out of context" (may be previous > > problem) > > These all happen because of the compiler optimizations (the -O2 switch > to GCC): > > > auth.o: auth.c > > gcc -g -O2 -Wall -I../include/ -c -o auth.o auth.c > > The optimizer rearranges code so that a single source line may be > split between several different code locations, that's why stepping in > GDB appears to execute a line several times. > > Btw, it's better to use -ggdb3 instead of -g, as that might give GDB > better debug info and help it help you during debugging. > > > These 2 problems render gdb unusuable and I have to resort on printfs > > for debugging. > > If you did this because you don't believe the debugger is showing you > the truth, then believe it, and use one of the 2 techniques below. > > First, you can always compile without optimizations. But that has a > disadvantage that you will be debugging a very different program than > you will later use in production, so I recommend this only as the last > resort. > > To debug an optimized program, you need to step through the code until > the source line you are interested in is no longer shown. For > example, in this case: > > > $ gdb nbssh > > > b ssh_userauth_kbdint > > > r 127.0.0.1 > > >> Breakpoint 1 file auth.c: function ssh_userauth_kbdint ... > > >> int err = 0; > > > n > > >> int ssh_userautrh_kbdint(SESSION *session ...) > > > n > > >> if (!username) > > type "n" a few more times, and you will see that the same few first > lines of the function are shown time and again. Wait until you get to > the line after "if (!username)", and then you can be sure that the > code produced by the first few lines of the function was executed in > its entirety, and the `err' variable's value can then be printed. > > As for this: > > > > p err > > >> variable "err" not available > > the optimizer could sometimes optimize a variable out of existence, or > put it into a register. So get used to the commands "info address" > and "info locals" to find out which local variables are stored where. > Here, too, while you are still in the function's prologue, GDB might > say that a variable is not in the current context, so step a while > into the function and try again. > > Debugging an optimized program like this takes used to, but it is > certainly doable, and the advantage is that you are debugging teh same > code you (or your clients) will be using in production. >
Technical Details
Message-ID:
<mailman.48.1111614309.28103.bug-gdb@gnu.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mailReferences:
<004301c52dbf$9a393110$0113263e@drwho> <01c52dd8$Blat.v2.4$82e72760@zahav.net.il>Show Full Headers
Complete Article Headers
X-Google-Thread: f5053,6e8b155fce2ecf1b X-Google-Attributes: gidf5053,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mail From: "Nikos Balkanas" <nbalk@hol.gr> Newsgroups: gnu.gdb.bug Subject: Re: gdb 6.1 blues Date: Wed, 23 Mar 2005 05:17:56 +0200 Lines: 96 Approved: bug-gdb@gnu.org Message-ID: <mailman.48.1111614309.28103.bug-gdb@gnu.org> References: <004301c52dbf$9a393110$0113263e@drwho> <01c52dd8$Blat.v2.4$82e72760@zahav.net.il> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: news.Stanford.EDU 1111613370 20554 199.232.76.165 (23 Mar 2005 21:29:30 GMT) X-Complaints-To: news@news.stanford.edu Cc: bug-gdb@gnu.org To: "Eli Zaretskii" <eliz@gnu.org> Envelope-to: bug-gdb@gnu.org X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-RAVMilter-Version: 8.3.3(snapshot 20020312) (kosmos) X-BeenThere: bug-gdb@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GDB, the GNU debugger" <bug-gdb.gnu.org> List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/bug-gdb>, <mailto:bug-gdb-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/pipermail/bug-gdb> List-Post: <mailto:bug-gdb@gnu.org> List-Help: <mailto:bug-gdb-request@gnu.org?subject=help> List-Subscribe: <http://lists.gnu.org/mailman/listinfo/bug-gdb>, <mailto:bug-gdb-request@gnu.org?subject=subscribe>