From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wvkyK+DZNGXoQDQAWB0awg (envelope-from ) for ; Sun, 22 Oct 2023 04:14:24 -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=XotuH5x7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A1ACA1E0C1; Sun, 22 Oct 2023 04:14:24 -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 7155D1E00F for ; Sun, 22 Oct 2023 04:14:22 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 760D9385800A for ; Sun, 22 Oct 2023 08:14:21 +0000 (GMT) Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id C98FF3858C66 for ; Sun, 22 Oct 2023 08:14:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C98FF3858C66 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 C98FF3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697962451; cv=none; b=dKhyb8ozJND9wIv2PAf8XcWeiWHt1PJJ5Q2Sb9LQP6vH8T7zirCIqAXXiS7TbDOBQYCzyhPRPMNBjfWfwJOY459ZNVxgPqqXKQHJA0OW7rD8Kx1T+I/yhUUBeanZRda+K3+tE4pZsR/RdviyfsE7fMgVYUhqIMi8yp0CX5dSh5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697962451; c=relaxed/simple; bh=s7cNPthKRXM4t4LZ2FffyTfG7UxSiRdm7skYnuGiRtE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=FTe0HGza7MBgucnqO1fM38G+HEVFfbLdfLWjXdCIEys52/+2S8Kv+mBb5hflTyx3xPku+2T/lFA+B3gAD+2bE5LQZfu/AlfhT+woRuXffa/Jz+fX7bXMM60p6696BAfAT6FmefgRhQo8jtOriWeUegT0JzksydKS/kj9JzYVfEY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-357cf6725acso1904325ab.3 for ; Sun, 22 Oct 2023 01:14:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697962449; x=1698567249; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=LiKiYkMZciUlcQhXtOPlbhp3u//ppAYJOFljDDrMHvk=; b=XotuH5x76AJxidYtsBQYTGCywXR2ypLpH/9QdhEFIx/0ZtnFhtEu4E2DicpKfTASEy 7Vr3MQBa5aveC5se5gB7hved1e7ujm+Fju7RUw2Pn6PcZPF/DNe+6iZkVOm7KpfXrrR/ cvPPuBHUj/5KrrrhJ5pVRAd92Owpm7EVZb6uJBYpyCi0O+2edWiPQSvUwnBi9EgTW0z/ NSmU4ICNOnImtBBh431sqscm+TJW9XLkPWuUJdrZ143d4tcprtF9vqCpqkAfJ9GEEgma vJMe8fkPbNESmGLvk7hos5nJePhtW5agTOjGB9zhZodTOfX+q+lldyQP1c+WEKsNKAkS ey/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697962449; x=1698567249; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LiKiYkMZciUlcQhXtOPlbhp3u//ppAYJOFljDDrMHvk=; b=LKGvWNMWmmtmZnJdDGeHTGzUfeos5ucmC7ptxNfeJo3HSI2Rt43xDLc7PXW4OTzUaS LfjKLPwMNOZ7+sy6bKCJDr00JaQN3ibtFqBMyuXcyZgvYoMz6VZPlINn10LuBch9NIKU bm37Br01eeYb1e8oOhhAeYkQTrkXeXexmU07U+1lUkftj2mm7S9iGKDSymWr/pZagICE t/oPfMSKcO2gtaWmvzrn/jqPK8RbUPVrV5Nhj7gjvGqoIwTJomyPOl9PhM1QlpTV/hPr VmQ0hQGLRySIRW5SFK03QXZrMGd8TgYKyAVfR06/ZyFVOO7RLbG4DarE3OMbEBUX7RgZ 32MA== X-Gm-Message-State: AOJu0Yyu2xBGtdeQX0jY0YMi0dbBX/SPsYGU38ZPcIbIl6aTjxr595/l 8O7WsCsz5nY8gekSOkIqDRKW2sy+vbuGBjZlXXrk8hDl8nQ= X-Google-Smtp-Source: AGHT+IHGR2Q8SeYoKNZ8g6baTwXsT/jLnB9OHICwJimYTLrFF3Zf4Ibw34Vwss86lJuU0BAJuBPA4SWG2AaSjATDWYQ= X-Received: by 2002:a92:c906:0:b0:34f:77bc:8d49 with SMTP id t6-20020a92c906000000b0034f77bc8d49mr6873800ilp.23.1697962448626; Sun, 22 Oct 2023 01:14:08 -0700 (PDT) MIME-Version: 1.0 From: Zeck S Date: Sun, 22 Oct 2023 03:13:26 -0500 Message-ID: Subject: [RFC][PATCH?] fixed some segfaults and bugs in mdebug support To: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="00000000000097aad2060849b0d8" X-Spam-Status: No, score=-10.3 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 --00000000000097aad2060849b0d8 Content-Type: text/plain; charset="UTF-8" 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 != NULL); would fail. info types would segfault The second problem was memory corruption. struct global_block is a larger 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 == GLOBAL_BLOCK). Failing to allocate this correctly leads to crashes for me (usually) in set_compunit_symtab where the assertion gdb_assert (gb->compunit_symtab == 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_stmt as true, do it always went down the /* Ignore non-statements. */ path in its main loop. I looked in the gdb/testsuite directory, and I don't see a directory for mips or mdebug? Unsure how to set up a test for this. To make files with 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) 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_BLOCK }; 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 = lineno; - lt->item[lt->nitems].is_stmt = 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, struct objfile *objfile) /* All symtabs must have at least two blocks. */ bv = 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) -{ - struct block *retval = new (&objfile->objfile_obstack) global_block; - - if (type == 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 * --00000000000097aad2060849b0d8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
First off, I apologize if I'm doing this process wrong= . I have sent an email to assign@gnu.org<= /a> 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 no= t sure exactly what is required for these changes.

Here's what I= fixed in mdebug support.=C2=A0

info sym funcName would segfault
= The first problem was that no compunit_symtab was set for the global_block = on blockvectors=C2=A0in=C2=A0 new_symtab. This caused a crash in block.c. initialize_block_iterator calle= d get_block_compunit_symtab and the assertion=C2=A0gdb_assert (gb->compu= nit_symtab !=3D NULL); would fail.

info types would segfault
The = second problem was memory corruption. struct global_block is a larger and d= ifferent 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_s= ymtab where the assertion=C2=A0=C2=A0gdb_assert (gb->compunit_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 w= orked because add_line never set .is_stmt to true, so in symtab.c find_line= _common never saw item->is_stmt as true, do it always went down the /* I= gnore non-statements. */ path in its main loop.

I looked in the gdb/= testsuite directory, and I don't see a directory for mips or mdebug? Un= sure how to set up a test for this. To make files with mdebug symbols, I us= ed 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 t= his symbol format. I can connect vscode to gdb and gdb to an n64 emulator w= ith a gdb stub to debug with symbols)

diff --git a/gdb/mdebugread.c = b/gdb/mdebugread.c
index 4b0a1eb255f..9cb30ce0acd 100644
--- a/gdb/md= ebugread.c
+++ b/gdb/mdebugread.c
@@ -239,9 +239,6 @@ enum block_type= { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
=C2=A0static struct block *new_= block (struct objfile *objfile,
=C2=A0 enum block_type, enum language= );
=C2=A0
-static struct block *new_global_block (struct objfile *obj= file,
- enum block_type, enum language);
-
=C2=A0static struct = compunit_symtab *new_symtab (const char *, int, struct objfile *);
=C2= =A0
=C2=A0static struct linetable *new_linetable (int);
@@ -4545,7 +4= 542,6 @@ add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int las= t)
=C2=A0 =C2=A0 =C2=A0return lineno;
=C2=A0
=C2=A0 =C2=A0lt->i= tem[lt->nitems].line =3D lineno;
- =C2=A0lt->item[lt->nitems].i= s_stmt =3D 1;
=C2=A0 =C2=A0lt->item[lt->nitems++].set_unrelocated_= pc (unrelocated_addr (adr << 2));
=C2=A0 =C2=A0return lineno;
= =C2=A0}
@@ -4638,10 +4634,9 @@ new_symtab (const char *name, int maxline= s, struct objfile *objfile)
=C2=A0
=C2=A0 =C2=A0/* All symtabs must h= ave at least two blocks. =C2=A0*/
=C2=A0 =C2=A0bv =3D new_bvect (2);
= - =C2=A0bv->set_block (GLOBAL_BLOCK, new_global_block (objfile, NON_FUNC= TION_BLOCK, lang));
+ =C2=A0bv->set_block (GLOBAL_BLOCK, new_block (o= bjfile, NON_FUNCTION_BLOCK, lang));
=C2=A0 =C2=A0bv->set_block (STATI= C_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, lang));
=C2=A0 =C2=A0bv= ->static_block ()->set_superblock (bv->global_block ());
- =C2= =A0bv->global_block ()->set_compunit_symtab(cust);
=C2=A0 =C2=A0cu= st->set_blockvector (bv);
=C2=A0
=C2=A0 =C2=A0cust->set_debugfo= rmat ("ECOFF");
@@ -4740,21 +4735,6 @@ new_block (struct objfi= le *objfile, enum block_type type,
=C2=A0 =C2=A0return retval;
=C2=A0= }
=C2=A0
-static struct block *
-new_global_block (struct objfile = *objfile, enum block_type type,
- =C2=A0 enum language language)
-{<= br>- =C2=A0struct block *retval =3D new (&objfile->objfile_obstack) = global_block;
-
- =C2=A0if (type =3D=3D FUNCTION_BLOCK)
- =C2=A0 = =C2=A0retval->set_multidict (mdict_create_linear_expandable (language));=
- =C2=A0else
- =C2=A0 =C2=A0retval->set_multidict (mdict_create_h= ashed_expandable (language));
-
- =C2=A0return retval;
-}
-
= -
=C2=A0/* Create a new symbol with printname NAME. =C2=A0*/
=C2=A0=C2=A0static struct symbol *
--00000000000097aad2060849b0d8--