From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9437 invoked by alias); 2 Dec 2011 04:32:33 -0000 Received: (qmail 9405 invoked by uid 22791); 2 Dec 2011 04:32:31 -0000 X-SWARE-Spam-Status: No, hits=0.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KAM_STOCKTIP,RCVD_IN_DNSWL_LOW,TW_DB X-Spam-Check-By: sourceware.org Received: from mail-iy0-f169.google.com (HELO mail-iy0-f169.google.com) (209.85.210.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Dec 2011 04:32:07 +0000 Received: by iapp10 with SMTP id p10so951899iap.0 for ; Thu, 01 Dec 2011 20:32:06 -0800 (PST) Received: by 10.42.178.66 with SMTP id bl2mr448077icb.9.1322800326555; Thu, 01 Dec 2011 20:32:06 -0800 (PST) Received: from [222.205.38.3] ([222.205.38.3]) by mx.google.com with ESMTPS id dd36sm29599529ibb.7.2011.12.01.20.32.03 (version=SSLv3 cipher=OTHER); Thu, 01 Dec 2011 20:32:05 -0800 (PST) Message-ID: <4ED8534D.2050100@gmail.com> Date: Fri, 02 Dec 2011 04:32:00 -0000 From: asmwarrior User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.6.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch] avoid the crash of gdb+pretty printer on initialized local variables References: <4ED379D8.4060808@gmail.com> In-Reply-To: <4ED379D8.4060808@gmail.com> Content-Type: multipart/mixed; boundary="------------060307000503050800010104" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-12/txt/msg00034.txt.bz2 This is a multi-part message in MIME format. --------------060307000503050800010104 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 2239 Hi, gdb developers. When debugger with python pretty printer, I sometimes get the gdb crash when I try to show the value of uninitialized local variables. As you know, an uninitialized local variable can contain some random value, so the pretty printer try to interpret those values, and can cause the gdb to an long loop or crash. The patch is just a work-around/hack to handle this problem. I just first check if the symbol is a local variable, and then check the current line SAL is smaller than the variable's declaration line. If true, which means this local variable is OK to show, if not, than I just skip it. The first patch try to deal with the "info locals" problem, the local variable defined later than the current line will be skipped. The second patch try to skip/filter the same local variables. For example: void fun() { wxString *psty = (wxString*) NULL; wxString wxStr(L"wxString"); wxStr += L" Value"; std::string stdStr("std::string"); stdStr.append(" value"); std::map m; m[0] = "000"; m[1] = "111"; //break point here, we stop here wxString& wxStrRef = wxStr; wxStrRef += L" Ref"; std::string& stdStrRef = stdStr; stdStrRef += " Ref"; std::list l = {"a", "b", "c"}; std::vector v = {"a", "b", "c"}; std::queue q; q.push("a"); q.push("b"); std::stack s; s.push("a"); s.push("b"); } Now, you have stopped on the breakpoint. the local variable "l,v,q" is after the breakpoint line. If you try to run "print v", or "info locals", then gdb will crash (I'm using gdb cvs build under WindowsXP, mingw, python 2.7) I believe that this patch will not be applied, because it is just a hack, right? I just also CC to mingw maillist hope they have some interests. Basically, gdb should alive with out any crash in any condition, but sometimes, I think a workaround is also necessary. I have see that in QTcreator, when they want to show the contents of a stl container, it do many sanity check. like: The length of the std::vector should be positive, and it's size should be limited. Also many other sanity checks asmwarrior ollydbg from codeblocks forum --------------060307000503050800010104 Content-Type: text/x-c++; name="avoid_uninitial_crash_stack.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="avoid_uninitial_crash_stack.patch" Content-length: 732 gdb/stack.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index c51832e..317570d 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1825,6 +1825,10 @@ iterate_over_block_locals (struct block *b, { struct dict_iterator iter; struct symbol *sym; + struct frame_info *frame; + struct symtab_and_line sal; + frame = get_selected_frame (NULL) ; + find_frame_sal (frame, &sal); ALL_BLOCK_SYMBOLS (b, iter, sym) { @@ -1836,6 +1840,8 @@ iterate_over_block_locals (struct block *b, case LOC_COMPUTED: if (SYMBOL_IS_ARGUMENT (sym)) break; + if(sym->line>= sal.line) + break; (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data); break; --------------060307000503050800010104 Content-Type: text/x-c++; name="avoid_uninitial_crash_print.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="avoid_uninitial_crash_print.patch" Content-length: 1621 gdb/symtab.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 65e4248..2047351 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1730,6 +1730,8 @@ lookup_block_symbol (const struct block *block, const char *name, { struct dict_iterator iter; struct symbol *sym; + struct frame_info *frame; + struct symtab_and_line sal; if (!BLOCK_FUNCTION (block)) { @@ -1739,7 +1741,20 @@ lookup_block_symbol (const struct block *block, const char *name, { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain)) - return sym; + { + if(SYMBOL_CLASS (sym)==LOC_LOCAL + ||SYMBOL_CLASS (sym)==LOC_REGISTER + ||SYMBOL_CLASS (sym)==LOC_COMPUTED) + { + frame = get_selected_frame (NULL) ; + find_frame_sal (frame, &sal); + if( block == get_frame_block (frame, 0) + && sym->line >= sal.line) + return NULL; + } + return sym; + } + } return NULL; } @@ -1763,7 +1778,17 @@ lookup_block_symbol (const struct block *block, const char *name, sym_found = sym; if (!SYMBOL_IS_ARGUMENT (sym)) { - break; + if(SYMBOL_CLASS (sym)==LOC_LOCAL + ||SYMBOL_CLASS (sym)==LOC_REGISTER + ||SYMBOL_CLASS (sym)==LOC_COMPUTED) + { + frame = get_selected_frame (NULL) ; + find_frame_sal (frame, &sal); + if(block == get_frame_block (frame, 0) + && sym->line >= sal.line) + sym_found = NULL; + } + break; } } } --------------060307000503050800010104--