From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ShYmCxqKEmCjaQAAWB0awg (envelope-from ) for ; Thu, 28 Jan 2021 04:55:38 -0500 Received: by simark.ca (Postfix, from userid 112) id 180CC1EF80; Thu, 28 Jan 2021 04:55:38 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1FBF31E945 for ; Thu, 28 Jan 2021 04:55:37 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 709E2386102A; Thu, 28 Jan 2021 09:55:36 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 2D9F13861018 for ; Thu, 28 Jan 2021 09:55:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2D9F13861018 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4212CAC97; Thu, 28 Jan 2021 09:55:32 +0000 (UTC) Subject: Re: [PATCH][gdb/breakpoints] Fix longjmp master breakpoint with separate debug info To: Tom Tromey References: <20210127143115.GA11549@delia> <87v9bidptm.fsf@tromey.com> From: Tom de Vries Message-ID: <6a0c1c97-4acc-5a50-4ae3-3279e51493d9@suse.de> Date: Thu, 28 Jan 2021 10:55:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <87v9bidptm.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------46BFFA0487AE27A1A224851C" Content-Language: en-US X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------46BFFA0487AE27A1A224851C Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 1/27/21 10:37 PM, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> 2021-01-27 Tom de Vries > > Tom> PR breakpoints/27205 > Tom> * breakpoint.c (create_longjmp_master_breakpoint_probe) > Tom> (create_longjmp_master_breakpoint_names): New function, factored out > Tom> of ... > Tom> (create_longjmp_master_breakpoint): ... here. Only try to install > Tom> longjmp_names breakpoints in libc.so/libc.so.debug if installing probe > Tom> breakpoint in libc.so failed. > > This looks reasonable to me. Thanks for doing it. > > Tom> + /* Skip separate debug object. */ > Tom> + if (obj->separate_debug_objfile_backlink) > > Normally this would be written != nullptr. > Ack, fixed. > Tom> + /* Iterate over separate debug objects and try longjmp_names > Tom> + kind breakpoints. */ > Tom> + for (objfile *sepdebug = obj->separate_debug_objfile; > Tom> + sepdebug != nullptr; sepdebug = sepdebug->separate_debug_objfile) > Tom> + if (create_longjmp_master_breakpoint_names (sepdebug)) > Tom> + break; > > I guess this can't use separate_debug_iterator / separate_debug_range > since that returns the parent objfile first. Ah, I didn't know about this iterator. I think this is precisely what we need (there is some extra code before this bit that calls create_longjmp_master_breakpoint_names (obj), so we could eliminate that). So, thanks a lot for pointing that out :) [ BTW, I think separate_debug_iterator / separate_debug_range is a bit of a misnomer, if it iterates over the parent obj first. It iterates over all the objects that could contain debug information, also if there's no separate debug info to begin with, f.i. if the parent object is unstripped and contains all the debug info. So perhaps debug_objfile_iterator / debug_objfile_range is more appropriate ? ] Anyway, updated the patch to use separate_debug_range, attached below. Will commit shortly. Thanks, - Tom --------------46BFFA0487AE27A1A224851C Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-breakpoints-Fix-longjmp-master-breakpoint-with-separate-debug-info.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename*0="0001-gdb-breakpoints-Fix-longjmp-master-breakpoint-with-sepa"; filename*1="rate-debug-info.patch" [gdb/breakpoints] Fix longjmp master breakpoint with separate debug info When running test-case gdb.base/longjmp.exp with target board unix/-m32, = we run into: =2E.. (gdb) next^M Warning:^M Cannot insert breakpoint 0.^M Cannot access memory at address 0x7dbf7353^M ^M __libc_siglongjmp (env=3D0x804a040 , val=3D1) at longjmp.c:28^M 28 longjmps++;^M (gdb) FAIL: gdb.base/longjmp.exp: next over longjmp(1) =2E.. The failure to access memory happens in i386_get_longjmp_target and is du= e to glibc having pointer encryption (aka "pointer mangling" or "pointer guard= ") of the long jump buffer. This is a known problem. In create_longjmp_master_breakpoint (which attempts to install a master longjmp breakpoint) a preference scheme is present, which installs a probe breakpoint if a libc:longjmp probe is present, and otherwise falls = back to setting breakpoints at the names in the longjmp_names array. But in fact, both the probe breakpoint and the longjmp_names breakpoints = are set. The latter ones are set when processing libc.so.debug, and the form= er one when processing libc.so. In other words, this is the longjmp variant= of PR26881, which describes the same problem for master exception breakpoint= s. This problem only triggers when the glibc debug info package is installed= , which is not due to the debug info itself in libc.so.debug, but due to th= e minimal symbols (because create_longjmp_master_breakpoint uses minimal sy= mbols to translate the longjmp_names to addresses). The problem doesn't trigger for -m64, because there tdep->jb_pc_offset is= not set. Fix this similar to commit 1940319c0ef (the fix for PR26881): only instal= l longjmp_names breakpoints in libc.so/libc.so.debug if installing the libc:longjmp probe in libc.so failed. Tested on x86_64-linux. gdb/ChangeLog: 2021-01-27 Tom de Vries PR breakpoints/27205 * breakpoint.c (create_longjmp_master_breakpoint_probe) (create_longjmp_master_breakpoint_names): New function, factored out of ... (create_longjmp_master_breakpoint): ... here. Only try to install longjmp_names breakpoints in libc.so/libc.so.debug if installing probe breakpoint in libc.so failed. --- gdb/breakpoint.c | 182 +++++++++++++++++++++++++++++++++----------------= ------ 1 file changed, 108 insertions(+), 74 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 70a4d0e1690..70b0d88cb45 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -3327,100 +3327,134 @@ create_overlay_event_breakpoint (void) } } =20 -static void -create_longjmp_master_breakpoint (void) +/* Install a master longjmp breakpoint for OBJFILE using a probe. Retur= n + true if a breakpoint was installed. */ + +static bool +create_longjmp_master_breakpoint_probe (objfile *objfile) { - scoped_restore_current_program_space restore_pspace; + struct gdbarch *gdbarch =3D objfile->arch (); + struct breakpoint_objfile_data *bp_objfile_data + =3D get_breakpoint_objfile_data (objfile); =20 - for (struct program_space *pspace : program_spaces) + if (!bp_objfile_data->longjmp_searched) { - set_current_program_space (pspace); + std::vector ret + =3D find_probes_in_objfile (objfile, "libc", "longjmp"); =20 - for (objfile *objfile : current_program_space->objfiles ()) + if (!ret.empty ()) { - int i; - struct gdbarch *gdbarch; - struct breakpoint_objfile_data *bp_objfile_data; + /* We are only interested in checking one element. */ + probe *p =3D ret[0]; =20 - gdbarch =3D objfile->arch (); + if (!p->can_evaluate_arguments ()) + { + /* We cannot use the probe interface here, + because it does not know how to evaluate + arguments. */ + ret.clear (); + } + } + bp_objfile_data->longjmp_probes =3D ret; + bp_objfile_data->longjmp_searched =3D 1; + } =20 - bp_objfile_data =3D get_breakpoint_objfile_data (objfile); + if (bp_objfile_data->longjmp_probes.empty ()) + return false; =20 - if (!bp_objfile_data->longjmp_searched) - { - std::vector ret - =3D find_probes_in_objfile (objfile, "libc", "longjmp"); + for (probe *p : bp_objfile_data->longjmp_probes) + { + struct breakpoint *b; =20 - if (!ret.empty ()) - { - /* We are only interested in checking one element. */ - probe *p =3D ret[0]; + b =3D create_internal_breakpoint (gdbarch, + p->get_relocated_address (objfile), + bp_longjmp_master, + &internal_breakpoint_ops); + b->location =3D new_probe_location ("-probe-stap libc:longjmp"); + b->enable_state =3D bp_disabled; + } =20 - if (!p->can_evaluate_arguments ()) - { - /* We cannot use the probe interface here, - because it does not know how to evaluate - arguments. */ - ret.clear (); - } - } - bp_objfile_data->longjmp_probes =3D ret; - bp_objfile_data->longjmp_searched =3D 1; - } + return true; +} =20 - if (!bp_objfile_data->longjmp_probes.empty ()) - { - for (probe *p : bp_objfile_data->longjmp_probes) - { - struct breakpoint *b; - - b =3D create_internal_breakpoint (gdbarch, - p->get_relocated_address (objfile), - bp_longjmp_master, - &internal_breakpoint_ops); - b->location =3D new_probe_location ("-probe-stap libc:longjmp"); - b->enable_state =3D bp_disabled; - } +/* Install master longjmp breakpoints for OBJFILE using longjmp_names. + Return true if at least one breakpoint was installed. */ + +static bool +create_longjmp_master_breakpoint_names (objfile *objfile) +{ + struct gdbarch *gdbarch =3D objfile->arch (); + if (!gdbarch_get_longjmp_target_p (gdbarch)) + return false; =20 + struct breakpoint_objfile_data *bp_objfile_data + =3D get_breakpoint_objfile_data (objfile); + unsigned int installed_bp =3D 0; + + for (int i =3D 0; i < NUM_LONGJMP_NAMES; i++) + { + struct breakpoint *b; + const char *func_name; + CORE_ADDR addr; + struct explicit_location explicit_loc; + + if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) + continue; + + func_name =3D longjmp_names[i]; + if (bp_objfile_data->longjmp_msym[i].minsym =3D=3D NULL) + { + struct bound_minimal_symbol m; + + m =3D lookup_minimal_symbol_text (func_name, objfile); + if (m.minsym =3D=3D NULL) + { + /* Prevent future lookups in this objfile. */ + bp_objfile_data->longjmp_msym[i].minsym =3D &msym_not_found; continue; } + bp_objfile_data->longjmp_msym[i] =3D m; + } =20 - if (!gdbarch_get_longjmp_target_p (gdbarch)) - continue; + addr =3D BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i])= ; + b =3D create_internal_breakpoint (gdbarch, addr, bp_longjmp_master= , + &internal_breakpoint_ops); + initialize_explicit_location (&explicit_loc); + explicit_loc.function_name =3D ASTRDUP (func_name); + b->location =3D new_explicit_location (&explicit_loc); + b->enable_state =3D bp_disabled; + installed_bp++; + } =20 - for (i =3D 0; i < NUM_LONGJMP_NAMES; i++) - { - struct breakpoint *b; - const char *func_name; - CORE_ADDR addr; - struct explicit_location explicit_loc; + return installed_bp > 0; +} =20 - if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) - continue; +/* Create a master longjmp breakpoint. */ =20 - func_name =3D longjmp_names[i]; - if (bp_objfile_data->longjmp_msym[i].minsym =3D=3D NULL) - { - struct bound_minimal_symbol m; +static void +create_longjmp_master_breakpoint (void) +{ + scoped_restore_current_program_space restore_pspace; =20 - m =3D lookup_minimal_symbol_text (func_name, objfile); - if (m.minsym =3D=3D NULL) - { - /* Prevent future lookups in this objfile. */ - bp_objfile_data->longjmp_msym[i].minsym =3D &msym_not_found; - continue; - } - bp_objfile_data->longjmp_msym[i] =3D m; - } + for (struct program_space *pspace : program_spaces) + { + set_current_program_space (pspace); =20 - addr =3D BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]= ); - b =3D create_internal_breakpoint (gdbarch, addr, bp_longjmp_maste= r, - &internal_breakpoint_ops); - initialize_explicit_location (&explicit_loc); - explicit_loc.function_name =3D ASTRDUP (func_name); - b->location =3D new_explicit_location (&explicit_loc); - b->enable_state =3D bp_disabled; - } + for (objfile *obj : current_program_space->objfiles ()) + { + /* Skip separate debug object, it's handled in the loop below. */ + if (obj->separate_debug_objfile_backlink !=3D nullptr) + continue; + + /* Try a probe kind breakpoint on main objfile. */ + if (create_longjmp_master_breakpoint_probe (obj)) + continue; + + /* Try longjmp_names kind breakpoints on main and separate_debug + objfiles. */ + for (objfile *debug_objfile : obj->separate_debug_objfiles ()) + if (create_longjmp_master_breakpoint_names (debug_objfile)) + break; } } } --------------46BFFA0487AE27A1A224851C--