From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 620 invoked by alias); 4 Dec 2011 01:41:47 -0000 Received: (qmail 604 invoked by uid 22791); 4 Dec 2011 01:41:46 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_DB,TW_SM 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; Sun, 04 Dec 2011 01:41:33 +0000 Received: by iapp10 with SMTP id p10so4260754iap.0 for ; Sat, 03 Dec 2011 17:41:33 -0800 (PST) Received: by 10.50.42.199 with SMTP id q7mr4699865igl.41.1322962893221; Sat, 03 Dec 2011 17:41:33 -0800 (PST) Received: from [192.168.1.102] ([218.109.112.215]) by mx.google.com with ESMTPS id cz1sm8793688ibb.11.2011.12.03.17.41.30 (version=SSLv3 cipher=OTHER); Sat, 03 Dec 2011 17:41:32 -0800 (PST) Message-ID: <4EDAD0B3.80505@gmail.com> Date: Sun, 04 Dec 2011 01:41:00 -0000 From: asmwarrior User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: [patch] avoid the crash of gdb+pretty printer on initialized local variables References: <4ED379D8.4060808@gmail.com> <4ED8534D.2050100@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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/msg00089.txt.bz2 On 2011-12-3 0:50, Tom Tromey wrote: >>>>>> ">" == ext asmwarrior writes: > >>> When debugger with python pretty printer, I sometimes get the gdb crash >>> when I try to show the value of uninitialized local variables. > > gdb should not crash. > > Is this that mingw-builds-only problem that keeps popping up? Thanks for the reply and comments. Yes, I guess it is only the mingw gdb problem, I have no linux at the moment, but in the Codeblocks' forum, I hear no Linux users complained this kind of crash of gdb on linux. > I forget, something to do with not using the right gcc flag? My app was build with -O0 and -g, no extra flag is used. > >>> 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. > > This is not ok. First, due to optimization, lines can be smeared > around, leading to the wrong result here. Second, a variable can be > trashed for many reasons, like other bugs in the code. In this second > case it is still unacceptable for gdb to crash. > > In theory the existing code will detect memory access errors and cause > printing to stop early. If you have a case where this doesn't work > properly, make a reproducible test case. Yes, agreed, as I said, it is only a work around. I create this patch to only avoid the crash of gdb under mingw. The sample code below can easily cause the crash under mingw+gdb+python pretty printer. > >>> 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 > It was not easy to catch such crash problem under windows. By the way, I found a way to debug gdb under Codeblocks' IDE, see: http://forums.codeblocks.org/index.php/topic,15618.msg105064.html#msg105064 It has some advantages than just debug gdb under command line. (mentioned in the above link post) Hopefully it will help some Windows user to easily check the crash problem in the future. asmwarrior ollydbg from codeblocks' forum