From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 List-Id: --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--