From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 73DBB38618E6 for ; Wed, 27 Sep 2023 18:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73DBB38618E6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=osandov.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=osandov.com Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c724577e1fso20378065ad.0 for ; Wed, 27 Sep 2023 11:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20230601.gappssmtp.com; s=20230601; t=1695838885; x=1696443685; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tNVaoiTfMTlfvfw0+Bv+mAffDc8ivRA7di/gxNq8Ymo=; b=tn+0lL0wUXQr1rJbB3ej6/X7urwW8u/aWbtbDGUSu5rHMJJptyCHZywbppjbhxgF4D THX4EjBlaoLGpCQhlj9ugd2wEn5lNMbAPEWC2J8z8AZTW9iySnlzC94ym/6SCM0Ye/fA LrJJv1eqRld+Uin2ukZBcRTvPPvyCBaQ44nJ4BxWP/yJy5vDYX8k0sNYpaPH3Vh8NJi6 xsRgPp4OjlgIT+tuy3XxciuVOQ8bunRwhf1fMtfT4kNddV36cb+OCsi1b1ATT6YOu9yC XygwjFYzUIQpH1NuzpXZj21QRSRmfiYxE1p3MDRgj7j5rZg6DYY1S5yHm6bChIbYu5+Y 4rpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695838885; x=1696443685; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tNVaoiTfMTlfvfw0+Bv+mAffDc8ivRA7di/gxNq8Ymo=; b=vabF8IkTfdomiJJbxcrsIGexPpfj4H80whUSAMBI7eRl3jYfOjli6cKjvNwa4Myy8f Iy3X2bW2AXntiz9SzYlZrwSfHVaZE1XhSzAS+0hJAs4fEvCJdFi3V0IVddY4CbuKTDKN Et6g/iiiefClySaeh6/lXNyZLRkebftn33cKmWcJhkWXE8FWMkmKSFOfjIVWZRvRhGg4 z7zSY3L44SJ4icW91Fcso9My6wO5Ucep72k6XeXXa3Yqu8Rfp5EThP03djclAFudcpu5 kraJ+bP9t4MRKutJcmPnFii9te85n/cffeAd2nr9Lbd/Hw8pKTTCJdMDd6IyeMlbkTcg cYZQ== X-Gm-Message-State: AOJu0YzX+1WGeA7d90ZknjuDsC3oPwsXkgytkhXdrt1x+qeuRuI+1qn2 +whLn4jNSh9HVU557tHIG5P+ONG5nfQKjFgdqE8XRg== X-Google-Smtp-Source: AGHT+IE6o8aj97ExgLSmOXoDIktSZ5cEbZ7TD0cQ5kZl6xsVNMrOFfY9cYum5v9cT0z2w9qUSvgnRw== X-Received: by 2002:a17:902:f541:b0:1bc:2abb:4e98 with SMTP id h1-20020a170902f54100b001bc2abb4e98mr2855600plf.21.1695838885095; Wed, 27 Sep 2023 11:21:25 -0700 (PDT) Received: from telecaster.thefacebook.com ([2620:10d:c090:500::6:efab]) by smtp.gmail.com with ESMTPSA id u16-20020a170902e81000b001bf6ea340a9sm13397842plg.159.2023.09.27.11.21.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:21:24 -0700 (PDT) From: Omar Sandoval To: elfutils-devel@sourceware.org Subject: [PATCH 12/14] tests: Optionally dump all units in dwarf-getmacros Date: Wed, 27 Sep 2023 11:21:01 -0700 Message-ID: <4453f4ff42a3234e60438733bcf1147451b7c2a7.1695837512.git.osandov@fb.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,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: From: Omar Sandoval If instead of a CU offset an empty string is given as the second argument, dump all units. Signed-off-by: Omar Sandoval --- tests/ChangeLog | 3 +++ tests/dwarf-getmacros.c | 51 +++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index 4380c57f..97261444 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -17,6 +17,9 @@ * dwarf-getmacros.c (mac): Add DW_MACRO_define_sup, DW_MACRO_define_strx, DW_MACRO_undef_sup, and DW_MACRO_undef_strx cases to opcode switch statement. + (getmacros): New function. + (main): If second argument is empty, call getmacros on every unit. + Otherwise, call getmacros on given unit. 2023-04-21 Frank Ch. Eigler diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c index e291bfd2..8381d42c 100644 --- a/tests/dwarf-getmacros.c +++ b/tests/dwarf-getmacros.c @@ -121,26 +121,57 @@ include (Dwarf *dbg, Dwarf_Off macoff, ptrdiff_t token) } } +static void +getmacros (Dwarf *dbg, Dwarf_Die *die, bool new_style) +{ + for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0; + (off = dwarf_getmacros (die, mac, dbg, off)); ) + if (off == -1) + { + puts (dwarf_errmsg (-1)); + break; + } +} + int main (int argc, char *argv[]) { assert (argc >= 3); const char *name = argv[1]; - ptrdiff_t cuoff = strtol (argv[2], NULL, 0); bool new_style = argc > 3; int fd = open (name, O_RDONLY); Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); - Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem); - - for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0; - (off = dwarf_getmacros (cudie, mac, dbg, off)); ) - if (off == -1) - { - puts (dwarf_errmsg (dwarf_errno ())); - break; - } + if (argv[2][0] == '\0') + { + Dwarf_CU *cu = NULL; + Dwarf_Die cudie, subdie; + uint8_t unit_type; + while (dwarf_get_units (dbg, cu, &cu, NULL, + &unit_type, &cudie, &subdie) == 0) + { + Dwarf_Die *die = (unit_type == DW_UT_skeleton + ? &subdie : &cudie); + if (! dwarf_hasattr (die, DW_AT_macro_info) + && ! dwarf_hasattr (die, DW_AT_GNU_macros) + && ! dwarf_hasattr (die, DW_AT_macros)) + continue; + printf ("CU %s\n", dwarf_diename (die)); + getmacros (dbg, die, new_style); + } + } + else + { + ptrdiff_t cuoff = strtol (argv[2], NULL, 0); + Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem); + if (cudie == NULL) + { + puts (dwarf_errmsg (-1)); + return 1; + } + getmacros (dbg, cudie, new_style); + } dwarf_end (dbg); -- 2.41.0