From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id XAcvHyUPN2W8cDUAWB0awg (envelope-from ) for ; Mon, 23 Oct 2023 20:26:13 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fsE2IPwJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 715151E0C1; Mon, 23 Oct 2023 20:26:13 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 31AE21E091 for ; Mon, 23 Oct 2023 20:26:11 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EDBF385840E for ; Tue, 24 Oct 2023 00:26:10 +0000 (GMT) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 47C193858C66 for ; Tue, 24 Oct 2023 00:25:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47C193858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 47C193858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698107152; cv=none; b=UtGXmnvz+ByqbyBTY+wNoGSzFf7T1T1bPbFhZHumxknndtIbiFiQCkUqKZQ0DaTGiVXClogC73rFLCZCdEG0+zy40SOUj47E10Da/XT9G/tfYQDZ1MOfAwJYxWItzYgZKxc+7wdjq1Nts7yt+gNX/GdireVRhGtuhLXhHyAVrBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698107152; c=relaxed/simple; bh=lS8EonI8qSw8XJCdA7iVRQtriNpUlZ6Lzl+T2/iwbng=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=EpOTK7Js0uXfrNifZJKEqG5UN3WitFWWLCEE+7NulyWaio57oKpG3pH/PcIiSG4l9Tt1YQiBKF6iGU+2SMWrPf4C72rtrLJQqNuaFVL4Jgsfuc3R+jYcQ9Id5xsu+b/m544F8K9xAy0v4BA1oeqw+oZqC1ZFPdFsjyPyG+SXvfE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-27d8e2ac2b1so2502287a91.2 for ; Mon, 23 Oct 2023 17:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698107134; x=1698711934; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DuES2Xx52FTTIY4TTQem+DuWJGIdaYTbn8MduqkuDNE=; b=fsE2IPwJxTBs66Yn2OppdPWt5EwDFB+OD/jy+WnyECP9QF5h0u0YMjNN2yZEbsj3s5 4rkKwihyxJ8lDK07x/mPxmw4dpafiQQWZaH2hUNpL2gfBPqTKoO1dpLkOnKoEZnBuGiz U4Jl2vXBprzng8CSIu1YWz2dxNb82y2Q9e/qmFKyf/6sZ4XZcVdJWsXpbbewd38LCnnN B9VQYCVxorFVplFIqUJ3pUZPpBI0r2O69rVwdj2wCADjodJD4GeLc+iYNH4Dz3H3d4wM PXvdX9JYozKW39hsWf9ohHXiC0fnJVhPCCAD78VhdJFD1O4ot1odr2wu0Aeho69IYLJi St1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698107134; x=1698711934; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DuES2Xx52FTTIY4TTQem+DuWJGIdaYTbn8MduqkuDNE=; b=fdI4Lnepsx8GH0sm/zO+O1K7JWL+f/i1VY8rsXtmiLRRUHIJEb5bOZy0TtZXqc+PiP m6DmF8m8aKWj9i6/XMD2XnWJNZ7zTp9YHnfRKKyXSdrLfx5LVeB1aQGSoXuiwwbFj0Pn M9IlyXBrLTUTxkyqhWCftsJrRE1LwqMu/GG7rbtrd/52vylnWVPKQzKWrV1CZX3pyYR7 1Mf4YagBj85gYhHqiJ1oGKiY+tDSa+Q3h7qN2XJkZhmIRzRDhzCvBDvIApS6Ajqz8mL0 xcUFzV0x1UhsDBqgG4aQPZNOl4ATk+GcG+vNE/jtSW/MIttLGZMVQnjptJ8w0F1kpCcL ZZVQ== X-Gm-Message-State: AOJu0Yy20ewKfvz32sq+KEXfdahu8J+7gWt0fiP68+FPbFzF+DOiNVd3 jvBpJO7qy9AYlP4+j0heCmJ66Wxwti6kn3X+1z4= X-Google-Smtp-Source: AGHT+IH7cYhKqji6zOkpS3FmRfVbDaLtQWKEcvc+GjnXNxV9VYH6s9wrgGSBqB4ABulJ9pj/Bz7ZF53rWrNEcTFuwQg= X-Received: by 2002:a17:90a:f2d2:b0:27d:3f43:d9c0 with SMTP id gt18-20020a17090af2d200b0027d3f43d9c0mr7874205pjb.24.1698107134145; Mon, 23 Oct 2023 17:25:34 -0700 (PDT) MIME-Version: 1.0 References: <877cnd4qy8.fsf@redhat.com> In-Reply-To: <877cnd4qy8.fsf@redhat.com> From: Zeck S Date: Mon, 23 Oct 2023 19:25:16 -0500 Message-ID: Subject: Re: [RFC][PATCH?] fixed some segfaults and bugs in mdebug support To: Andrew Burgess Cc: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="000000000000857b1906086b6034" X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org --000000000000857b1906086b6034 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Oh, I messed up the diff. Spoiled by github, never done it this way. The testing makes sense now. Might be the weekend before I can make much progress on that. Thanks for the fast reply! On Mon, Oct 23, 2023 at 4:40=E2=80=AFAM Andrew Burgess wrote: > Zeck S writes: > > > First off, I apologize if I'm doing this process wrong. I have sent an > > email to assign@gnu.org trying to get the paperwork required for > copyright > > assignment. I think that's the correct thing to do? > > > > While I wait on that, I'm not sure exactly what is required for these > > changes. > > > > Here's what I fixed in mdebug support. > > > > info sym funcName would segfault > > The first problem was that no compunit_symtab was set for the > global_block > > on blockvectors in new_symtab. This caused a crash in block.c. > > initialize_block_iterator called get_block_compunit_symtab and the > > assertion gdb_assert (gb->compunit_symtab !=3D NULL); would fail. > > > > info types would segfault > > The second problem was memory corruption. struct global_block is a larg= er > > and different type from plain block and blockvector is expected to have > > index 0 be a global_block struct. This can be seen done correctly in > jit.c > > near /* Now add the special blocks */ under if (i =3D=3D GLOBAL_BLOCK). > Failing > > to allocate this correctly leads to crashes for me (usually) in > > set_compunit_symtab where the assertion gdb_assert (gb->compunit_symta= b > =3D=3D > > NULL); would randomly fail. This fix is also in new_symtab. > > > > info line file:line did not work > > The third problem was finding lines never worked because add_line never > set > > .is_stmt to true, so in symtab.c find_line_common never saw item->is_st= mt > > as true, do it always went down the /* Ignore non-statements. */ path i= n > > its main loop. > > I was confused by this description as the only change I see is you > removing this line 'lt->item[lt->nitems].is_stmt =3D 1;' , but I suspect > you generated your diff the wrong way round. > > You should consider creating your diff as a git commit, then use 'git > send-email' to send out patches, I found this site > https://git-send-email.io/ a pretty useful guide for setting up git & > email sending. > > > > > I looked in the gdb/testsuite directory, and I don't see a directory fo= r > > mips or mdebug? Unsure how to set up a test for this. To make files wit= h > > mdebug symbols, I used the old IRIX IDO compiler running under a kind o= f > > qemu setup used by N64 game reverse engineering projects. (N64 dev is w= hy > > I'm interested in this symbol format. I can connect vscode to gdb and g= db > > to an n64 emulator with a gdb stub to debug with symbols) > > You might not need to add any new tests at all, IF you can identify some > existing tests that are fixed by your changes. > > Most tests are not separated based on which compiler or environment is > used, though clearly there are exceptions, e.g. gdb.arch/*.exp does > contain some architecture specific tests. Instead most tests are > written based on the GDB feature being tested. For example, > gdb.base/infoline.exp tests the 'info line' command. > > The expectation is that if someone has a more niche compiler or > environment then they will perform their own regression testing using > their setup. > > So, hopefully, if you can get the GDB tests running using your > toolchain, then without your patch you'll see some failures in (maybe) > gdb.base/infoline.exp, and after your patch some of the failures would > be resolved, you'd then mention some (or all) of these improvements in > your commit message. > > Of course, if your particular situation isn't covered by an existing > test then you might need to extend an existing test -- or create a new > test -- whatever seems most appropriate. > > > > > diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c > > index 4b0a1eb255f..9cb30ce0acd 100644 > > --- a/gdb/mdebugread.c > > +++ b/gdb/mdebugread.c > > @@ -239,9 +239,6 @@ enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOC= K > }; > > static struct block *new_block (struct objfile *objfile, > > enum block_type, enum language); > > > > -static struct block *new_global_block (struct objfile *objfile, > > - enum block_type, enum language); > > - > > static struct compunit_symtab *new_symtab (const char *, int, struct > > objfile *); > > > > static struct linetable *new_linetable (int); > > @@ -4545,7 +4542,6 @@ add_line (struct linetable *lt, int lineno, > CORE_ADDR > > adr, int last) > > return lineno; > > > > lt->item[lt->nitems].line =3D lineno; > > - lt->item[lt->nitems].is_stmt =3D 1; > > lt->item[lt->nitems++].set_unrelocated_pc (unrelocated_addr (adr << > 2)); > > return lineno; > > } > > @@ -4638,10 +4634,9 @@ new_symtab (const char *name, int maxlines, stru= ct > > objfile *objfile) > > > > /* All symtabs must have at least two blocks. */ > > bv =3D new_bvect (2); > > - bv->set_block (GLOBAL_BLOCK, new_global_block (objfile, > > NON_FUNCTION_BLOCK, lang)); > > + bv->set_block (GLOBAL_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, > > lang)); > > bv->set_block (STATIC_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, > > lang)); > > bv->static_block ()->set_superblock (bv->global_block ()); > > - bv->global_block ()->set_compunit_symtab(cust); > > cust->set_blockvector (bv); > > > > cust->set_debugformat ("ECOFF"); > > @@ -4740,21 +4735,6 @@ new_block (struct objfile *objfile, enum > block_type > > type, > > return retval; > > } > > > > -static struct block * > > -new_global_block (struct objfile *objfile, enum block_type type, > > - enum language language) > > Static functions should have a comment before them. In this case > something as simple as: > > /* Like new_block, but create a global_block. */ > > Though I wonder if we could/should just give new_block an extra > parameter so its declaration becomes: > > static struct block *new_block (struct objfile *objfile, > enum block_type, enum language, > bool global_block =3D false); > > Hopefully it's obvious how the new parameter would be used :) > > Thanks, > Andrew > > > > -{ > > - struct block *retval =3D new (&objfile->objfile_obstack) global_bloc= k; > > - > > - if (type =3D=3D FUNCTION_BLOCK) > > - retval->set_multidict (mdict_create_linear_expandable (language)); > > - else > > - retval->set_multidict (mdict_create_hashed_expandable (language)); > > - > > - return retval; > > -} > > - > > - > > /* Create a new symbol with printname NAME. */ > > > > static struct symbol * > > --000000000000857b1906086b6034 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Oh, I messed up the diff. Spoiled by github, never done it= this=C2=A0way.
The testing makes sense now. Might be the weekend before= I can make much progress on=C2=A0that.
Thanks for the fast reply!
=
On Mon= , Oct 23, 2023 at 4:40=E2=80=AFAM Andrew Burgess <aburgess@redhat.com> wrote:
Zeck S <zeck654321@gmail.com> writes:

> First off, I apologize if I'm doing this process wrong. I have sen= t an
> email to assign@gn= u.org trying to get the paperwork required for copyright
> assignment. I think that's the correct thing to do?
>
> While I wait on that, I'm not sure exactly what is required for th= ese
> changes.
>
> Here's what I fixed in mdebug support.
>
> info sym funcName would segfault
> The first problem was that no compunit_symtab was set for the global_b= lock
> on blockvectors in=C2=A0 new_symtab. This caused a crash in block.c. > initialize_block_iterator called get_block_compunit_symtab and the
> assertion gdb_assert (gb->compunit_symtab !=3D NULL); would fail. >
> info types would segfault
> The second problem was memory corruption. struct global_block is a lar= ger
> and different type from plain block and blockvector is expected to hav= e
> index 0 be a global_block struct. This can be seen done correctly in j= it.c
> near /* Now add the special blocks */ under if (i =3D=3D GLOBAL_BLOCK)= . Failing
> to allocate this correctly leads to crashes for me (usually) in
> set_compunit_symtab where the assertion=C2=A0 gdb_assert (gb->compu= nit_symtab =3D=3D
> NULL); would randomly fail. This fix is also in new_symtab.
>
> info line file:line did not work
> The third problem was finding lines never worked because add_line neve= r set
> .is_stmt to true, so in symtab.c find_line_common never saw item->i= s_stmt
> as true, do it always went down the /* Ignore non-statements. */ path = in
> its main loop.

I was confused by this description as the only change I see is you
removing this line 'lt->item[lt->nitems].is_stmt =3D 1;' , bu= t I suspect
you generated your diff the wrong way round.

You should consider creating your diff as a git commit, then use 'git send-email' to send out patches, I found this site
https://git-send-email.io/ a pretty useful guide for setting up git &a= mp;
email sending.

>
> I looked in the gdb/testsuite directory, and I don't see a directo= ry for
> mips or mdebug? Unsure how to set up a test for this. To make files wi= th
> mdebug symbols, I used the old IRIX IDO compiler running under a kind = of
> qemu setup used by N64 game reverse engineering projects. (N64 dev is = why
> I'm interested in this symbol format. I can connect vscode to gdb = and gdb
> to an n64 emulator with a gdb stub to debug with symbols)

You might not need to add any new tests at all, IF you can identify some existing tests that are fixed by your changes.

Most tests are not separated based on which compiler or environment is
used, though clearly there are exceptions, e.g. gdb.arch/*.exp does
contain some architecture specific tests.=C2=A0 Instead most tests are
written based on the GDB feature being tested.=C2=A0 For example,
gdb.base/infoline.exp tests the 'info line' command.

The expectation is that if someone has a more niche compiler or
environment then they will perform their own regression testing using
their setup.

So, hopefully, if you can get the GDB tests running using your
toolchain, then without your patch you'll see some failures in (maybe)<= br> gdb.base/infoline.exp, and after your patch some of the failures would
be resolved, you'd then mention some (or all) of these improvements in<= br> your commit message.

Of course, if your particular situation isn't covered by an existing test then you might need to extend an existing test -- or create a new
test -- whatever seems most appropriate.

>
> diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
> index 4b0a1eb255f..9cb30ce0acd 100644
> --- a/gdb/mdebugread.c
> +++ b/gdb/mdebugread.c
> @@ -239,9 +239,6 @@ enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLO= CK };
>=C2=A0 static struct block *new_block (struct objfile *objfile,
>=C2=A0 =C2=A0enum block_type, enum language);
>
> -static struct block *new_global_block (struct objfile *objfile,
> - enum block_type, enum language);
> -
>=C2=A0 static struct compunit_symtab *new_symtab (const char *, int, st= ruct
> objfile *);
>
>=C2=A0 static struct linetable *new_linetable (int);
> @@ -4545,7 +4542,6 @@ add_line (struct linetable *lt, int lineno, CORE= _ADDR
> adr, int last)
>=C2=A0 =C2=A0 =C2=A0 return lineno;
>
>=C2=A0 =C2=A0 lt->item[lt->nitems].line =3D lineno;
> -=C2=A0 lt->item[lt->nitems].is_stmt =3D 1;
>=C2=A0 =C2=A0 lt->item[lt->nitems++].set_unrelocated_pc (unreloca= ted_addr (adr << 2));
>=C2=A0 =C2=A0 return lineno;
>=C2=A0 }
> @@ -4638,10 +4634,9 @@ new_symtab (const char *name, int maxlines, str= uct
> objfile *objfile)
>
>=C2=A0 =C2=A0 /* All symtabs must have at least two blocks.=C2=A0 */ >=C2=A0 =C2=A0 bv =3D new_bvect (2);
> -=C2=A0 bv->set_block (GLOBAL_BLOCK, new_global_block (objfile,
> NON_FUNCTION_BLOCK, lang));
> +=C2=A0 bv->set_block (GLOBAL_BLOCK, new_block (objfile, NON_FUNCTI= ON_BLOCK,
> lang));
>=C2=A0 =C2=A0 bv->set_block (STATIC_BLOCK, new_block (objfile, NON_F= UNCTION_BLOCK,
> lang));
>=C2=A0 =C2=A0 bv->static_block ()->set_superblock (bv->global_= block ());
> -=C2=A0 bv->global_block ()->set_compunit_symtab(cust);
>=C2=A0 =C2=A0 cust->set_blockvector (bv);
>
>=C2=A0 =C2=A0 cust->set_debugformat ("ECOFF");
> @@ -4740,21 +4735,6 @@ new_block (struct objfile *objfile, enum block_= type
> type,
>=C2=A0 =C2=A0 return retval;
>=C2=A0 }
>
> -static struct block *
> -new_global_block (struct objfile *objfile, enum block_type type,
> -=C2=A0 =C2=A0enum language language)

Static functions should have a comment before them.=C2=A0 In this case
something as simple as:

=C2=A0 /* Like new_block, but create a global_block.=C2=A0 */

Though I wonder if we could/should just give new_block an extra
parameter so its declaration becomes:

=C2=A0 static struct block *new_block (struct objfile *objfile,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 enum block_type, enum languag= e,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool global_block =3D false);=

Hopefully it's obvious how the new parameter would be used :)

Thanks,
Andrew


> -{
> -=C2=A0 struct block *retval =3D new (&objfile->objfile_obstack= ) global_block;
> -
> -=C2=A0 if (type =3D=3D FUNCTION_BLOCK)
> -=C2=A0 =C2=A0 retval->set_multidict (mdict_create_linear_expandabl= e (language));
> -=C2=A0 else
> -=C2=A0 =C2=A0 retval->set_multidict (mdict_create_hashed_expandabl= e (language));
> -
> -=C2=A0 return retval;
> -}
> -
> -
>=C2=A0 /* Create a new symbol with printname NAME.=C2=A0 */
>
>=C2=A0 static struct symbol *

--000000000000857b1906086b6034--