From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10824 invoked by alias); 26 Sep 2014 18:00:07 -0000 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 Received: (qmail 10802 invoked by uid 89); 26 Sep 2014 18:00:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mail-ie0-f179.google.com Received: from mail-ie0-f179.google.com (HELO mail-ie0-f179.google.com) (209.85.223.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 26 Sep 2014 18:00:05 +0000 Received: by mail-ie0-f179.google.com with SMTP id tp5so11042288ieb.24 for ; Fri, 26 Sep 2014 11:00:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=UfN30bghuho2yw7hW1tw/RMgs1fj5F3xr6IfvLprQWw=; b=DEs39JsJ0RyCpf2sVvXqRMX0xE7nsJzbw2l0JUJbs8KlHpoqJXRmygYd8lgU0lSeNe ytm0rZgEpBVnxSEK/wIRqgX8m6hEJs8Rv5Tv6ffLFA6RaAAc4Os3lDJcC6w2gg4JgPFo 9XBA7mnahbjtWrFZi5T08JKxaCObHRkWCAYJbKsdnAY9yXEFwwyaiXRePlUVUsF7Gc68 sDXSv4D26ftVbMxUi5HaCZ98T+bQFNWdt7fNQmgBVBkW9/W09D+dxK1MbwKHQNUirJbJ gGaGX+JRHlx0syPntvyj3Eq6zi1iUddT3ynLdCEfZ4Qx5JU2DQKjWxAwu602sUm3drGR BvvQ== X-Gm-Message-State: ALoCoQkgOH4vpQcJ64Qa9MC1rhr1ilcDyi9QzrCbOvVNiJ47cFpDhQxIdz2sCaXDw62TFX8tvapY MIME-Version: 1.0 X-Received: by 10.42.92.129 with SMTP id t1mr28183170icm.59.1411754402772; Fri, 26 Sep 2014 11:00:02 -0700 (PDT) Received: by 10.107.162.205 with HTTP; Fri, 26 Sep 2014 11:00:02 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Sep 2014 18:00:00 -0000 Message-ID: Subject: Re: break on C++ global objects ctors From: Daniel Gutson To: Paul_Koning@dell.com Cc: gdb-patches , Martin Galvan Content-Type: multipart/mixed; boundary=90e6ba6147feb29ea80503fbaf44 X-IsSubscribed: yes X-SW-Source: 2014-09/txt/msg00795.txt.bz2 --90e6ba6147feb29ea80503fbaf44 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-length: 3546 I resurrect this issue since there was no satisfying solution. We went through the plugin solution, just to check the idea, and maybe later discuss a native (maybe gdb-gcc joint) solution. There were three possible approaches: - a regex-based approach, library-implementation independent, so the plugin does some magic looking for symbols and detecting which one have, placing breakpoints there, breaking at main and add a command in main to disable all the previous breakpoints. The attached file is a plugin that follows this approach. - a library-implementation dependent approach, that breaks in all the __static_initialization_and_destruction_0, then disassemblying them finding each call to a ctor, placing a breakpoint there with a "stepi" command. We are tempted to follow this approach but we ran out of time so we're using the previous one. And we don't know how portable this is (we checked x86 but need this tool for a number of other platforms, such as ARM and SPARC). I believe that __static_initialization_and_destruction_0 is generated for all platforms and with the same name but I'm not sure. - a dwarf-inspection based approach which we didn't deeply explore. Now, the plugin isn't perfect, has some corner cases, and required a huge amount of regex magic (specially due to C++ templates). Is there consensus that this could be done in a native command, such as "break-global-ctors" (and "break-global-dtors", which the plugin doesn't address either) ? Thanks, Daniel. ps: BTW, we found a lot of opportunities to improve of the python API that would make this plugin much simpler, but that will go to a separate thread. On Mon, Mar 31, 2014 at 11:41 AM, Daniel Gutson wrote: > On Mon, Mar 31, 2014 at 11:15 AM, wrote: >> >> On Mar 31, 2014, at 10:10 AM, Daniel Gutson wrote: >> >>> On Mon, Mar 31, 2014 at 10:56 AM, wrote: >>>> This certainly should be easily doable, just in gdb. FWIW, if you sta= rt a program with gdbserver and then connect to it from gdb ("target remote= " to gdbserver), the program is stopped at the first instruction, way befor= e "main". >>> >>> That doesn't solve how gdb detects the beginning of each ctor function. >> >> I don't know what problem you're referring to. A constructor is just a = function, which has a name, and you can set a breakpoint on it. >> >> If for some reason that's not working, that would be a bug, but I've use= d breakpoints on constructors for a long time and it seems to work when I t= ry it. > > The issue I need to add is to make gdb break at the beginning of the > construction of each (all) global object of the program. > Breaking at the beginning of the program does not solve this. Please > see my original with this clarification, so maybe I can be clearer. > > One possible solution is: add breaks in the ctors of ALL types, run, > and at main delete all those breakpoints. > Another solution is to do some handling of each > __static_initialization_and_destruction_0 which varies depending on > the context. > > >> >> paul > > > > -- > > Daniel F. Gutson > Chief Engineering Officer, SPD > > > San Lorenzo 47, 3rd Floor, Office 5 > > C=C3=B3rdoba, Argentina > > > Phone: +54 351 4217888 / +54 351 4218211 > > Skype: dgutson --=20 Daniel F. Gutson Chief Engineering Officer, SPD San Lorenzo 47, 3rd Floor, Office 5 C=C3=B3rdoba, Argentina Phone: +54 351 4217888 / +54 351 4218211 Skype: dgutson --90e6ba6147feb29ea80503fbaf44 Content-Type: text/x-python; charset=US-ASCII; name="BreakAtGlobals.py" Content-Disposition: attachment; filename="BreakAtGlobals.py" Content-Transfer-Encoding: base64 X-Attachment-Id: f_i0ju18mk0 Content-length: 4185 IyBCcmVha0F0R2xvYmFscy5weTogQSBHREIgc2NyaXB0IGZvciBzZXR0aW5n IGJyZWFrcG9pbnRzIGF0IGdsb2JhbCBjb25zdHJ1Y3RvcnMuCiMKIyBDb3B5 cmlnaHQgKEMpIDIwMTQgTWFydGluIEdhbHZhbiwgRGFuaWVsIEd1dHNvbiwg VGFsbGVyIFRlY2hub2xvZ2llcy4KIwojIEJyZWFrQXRHbG9iYWxzIG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