From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YCgaCGl4BWctVAYAWB0awg (envelope-from ) for ; Tue, 08 Oct 2024 14:22:33 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RMJ9qzhu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1DFC11E355; Tue, 8 Oct 2024 14:22:33 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-7.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=unavailable autolearn_force=no version=4.0.0 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 9E4571E05C for ; Tue, 8 Oct 2024 14:22:32 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F0FB385C6CC for ; Tue, 8 Oct 2024 18:22:32 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3127F385C6CC for ; Tue, 8 Oct 2024 18:22:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3127F385C6CC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3127F385C6CC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728411732; cv=none; b=vpqiSPqwE+LUnUAUUdOPE8Vd6LgyZ7Y8ZLpKhiKQfExHcCd/BLf6WUR8RFcEbM7Cj2yqhUGENVNvTOYothHEO06r9J2QC/dT7JQGBzJUJRieGcmUlN9xbHRXcwk+tlwspE5HNIe5a3EfOmWU5vp0E3ImWhXR8PBwhv7QGcwE0ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728411732; c=relaxed/simple; bh=5uqgaKiknVZYWC0Kb8gbXtMpV78oVNllfHONc1bYUnk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Xxa3OHUwnIOuAAgRXkP8jkvdwAT3XcOylqNlwcN8gsijDp0DqSkBNBEkdnmDVMma16MCKdJUvONrozgtKNAXmhHV9udpd+liG0BUpCuQ/1NoULFxtu2XUnal/erS27ZunNHB8iPWZshZPvwN9n21oSyiu8W9K6Cou1XpvVvTnpk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728411729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qqo7cIF5oceKU6eWdRAkebrzz5LrCzGu57MwoeMlIEg=; b=RMJ9qzhuuGGVPAPomyBKxA0XqZ7vH1MgXJTSh6zGkvul3dQ8s1ZEXw3415S+gxHyLqT26J g4OZcQJC4cbMdEW/j4uMqI/I/CM/UJnnaZBHDhL/IB2N33B4TJAhU9GSH5t/0Tup42Vcqs Nk0PQCO7xuhx3ktryltWUDeOsabtZnA= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-Ff12nl5gO6im0YrtZoDV6Q-1; Tue, 08 Oct 2024 14:22:08 -0400 X-MC-Unique: Ff12nl5gO6im0YrtZoDV6Q-1 Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-82d0daa1b09so780151139f.3 for ; Tue, 08 Oct 2024 11:22:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728411728; x=1729016528; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qqo7cIF5oceKU6eWdRAkebrzz5LrCzGu57MwoeMlIEg=; b=TrZ3i1FOKqP5Jn8ZjZf32W872TDnH1S8fqklwoxo0DKhVoXctJlTDhReiJakQjBFRE oGWmTiVuNaUa7aaKpKdbovZWR6zE8YQE8SQOs2XTCsSVAXHseWE0elAhcOvs5AR5yUqE boNE3c34/c+Z/Lt/SW/InOm/p0ZAKd19VbUOv8Ff64Vz2ipNBJ4I7cpZVfFBLP6jc2hd sgibV2HqbUf1A6jQ3Jth+SDAh8l/ctLhNwdTy+l77RtiaM8AnOBFR8ArY4R/QSzmLH+Y +c5eMNSGhXc9BzZTOlG1u0ZGk+bAg2cXBfov2d51049h1ra8OQ/OS306u8BcQty5ekkw JPeA== X-Forwarded-Encrypted: i=1; AJvYcCWHn/OGz6MebKfwCNOaEQMDYinmDPQAEkPYHTWJ/r4dsVz0wlh8M57Mt3INKAj8ZnwJw6rYiIvJ5aRjTg==@sourceware.org X-Gm-Message-State: AOJu0Yyi3xDHp1L/6y/IcHOs3AcqcpmE8IUG3pctR0X9XjPFNFLsY3YQ alFckBoVvneOFwlFve+KvByliMYN2FP6cTC5gR6Au2hsmF7NoS5sBuieuUOyWAZZTA4JJyYCGSw udH538T1QaWAwsYB1BZetW5o4/3DEKvmiGtRUp/4GrY9NahXtg30bBVZy7TU= X-Received: by 2002:a05:6602:6d13:b0:82c:f1f6:55b1 with SMTP id ca18e2360f4ac-834f7a7e961mr1631699539f.0.1728411728007; Tue, 08 Oct 2024 11:22:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMFQJTSWHOAAtkWSFtiT0/iOw75kY1afoi2fPKdXbnWTKXvs0OM0KshruSXsGWmnkN27oLxg== X-Received: by 2002:a05:6602:6d13:b0:82c:f1f6:55b1 with SMTP id ca18e2360f4ac-834f7a7e961mr1631696939f.0.1728411727570; Tue, 08 Oct 2024 11:22:07 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:92c5::1000? ([2804:14d:8084:92c5::1000]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-83503b305easm182504039f.47.2024.10.08.11.22.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Oct 2024 11:22:07 -0700 (PDT) Message-ID: Date: Tue, 8 Oct 2024 15:22:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 2/5] gdb: add "unwinder class" to frame unwinders To: Simon Marchi , gdb-patches@sourceware.org Cc: Eli Zaretskii References: <20241001184235.3710608-1-guinevere@redhat.com> <20241001184235.3710608-3-guinevere@redhat.com> From: Guinevere Larsen In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 On 10/3/24 3:46 PM, Simon Marchi wrote: > On 10/1/24 2:42 PM, Guinevere Larsen wrote: >> From: Guinevere Larsen >> >> A future patch will add a way to disable certain unwinders based on >> different characteristics. This patch aims to make it more convenient >> to disable related unwinders in bulk, such as architecture specific >> ones, by indentifying all unwinders by which part of the code adds it. > indentifying -> identifying > >> diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c >> index b69ae8596a2..afc1258c6a9 100644 >> --- a/gdb/frame-unwind.c >> +++ b/gdb/frame-unwind.c >> @@ -30,6 +30,17 @@ >> #include "dwarf2/frame-tailcall.h" >> #include "cli/cli-cmds.h" >> #include "inferior.h" >> +#include >> + >> +/* Conversion list between the enum for frame_unwind_class and >> + string. */ >> +static std::map unwind_class_conversion = >> +{ >> + {FRAME_UNWIND_GDB, "GDB"}, >> + {FRAME_UNWIND_ARCH, "ARCH"}, >> + {FRAME_UNWIND_EXTENSION, "EXTENSION"}, >> + {FRAME_UNWIND_DEBUGINFO, "DEBUGINFO"}, >> +}; > It's not reaaally a big deal, but using an std::map for this is kind of > heavyweight. It could probably be a simple array, still indexed by the > enum value. Personally, I used functions with switches to handle cases > this (see target_waitkind_str), because compilers can warn you if you > forget to handle an enumerator (which can easily happen when a new one > is added). Since I have 2 functions, one to convert from enum to string, and another from string to enum, I'll go with a simple array that makes it easy to do both. This is my proposed change: diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index ef05b658f94..10d9f2e9f88 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -34,12 +34,12 @@  /* Conversion list between the enum for frame_unwind_class and     string. */ -static std::map unwind_class_conversion = +static const char * unwind_class_conversion[] =  { -  {FRAME_UNWIND_GDB, "GDB"}, -  {FRAME_UNWIND_ARCH, "ARCH"}, -  {FRAME_UNWIND_EXTENSION, "EXTENSION"}, -  {FRAME_UNWIND_DEBUGINFO, "DEBUGINFO"}, + "GDB", + "ARCH", + "EXTENSION", + "DEBUGINFO",  };  /* Default sniffers, that must always be the first in the unwinder list, @@ -88,9 +88,8 @@ get_frame_unwind_table (struct gdbarch *gdbarch)  static const char *  frame_unwinder_class_str (frame_unwind_class uclass)  { -  auto location = unwind_class_conversion.find (uclass); -  gdb_assert (location != unwind_class_conversion.end ()); -  return location->second; +  gdb_assert (uclass < UNWIND_CLASS_NUMBER); +  return unwind_class_conversion[uclass];  }  /* Case insensitive search for a frame_unwind_class based on the given @@ -102,10 +101,10 @@ str_to_frame_unwind_class (const char *class_str)    /* Skip the prefix if present. */    if (strncasecmp (class_str, prefix, strlen(prefix)) == 0)      class_str += strlen (prefix); -  for (const auto &it : unwind_class_conversion) +  for (int i = 0; i < UNWIND_CLASS_NUMBER; i++) { -      if (strcasecmp (it.second, class_str) == 0) -       return it.first; +      if (strcasecmp (unwind_class_conversion[i], class_str) == 0) +       return (frame_unwind_class) i; }    error (_("Unknown frame unwind class: %s"), class_str);  } diff --git a/gdb/frame-unwind.h b/gdb/frame-unwind.h index f5ea8d9f690..555a5d98d5b 100644 --- a/gdb/frame-unwind.h +++ b/gdb/frame-unwind.h @@ -167,6 +167,8 @@ enum frame_unwind_class FRAME_UNWIND_DEBUGINFO,    /* The unwinder was created and handles target dependent things.  */ FRAME_UNWIND_ARCH, +  /* Meta enum value, to ensure we're always sent a valid unwinder class.  */ + UNWIND_CLASS_NUMBER,  }; > > Otherwise, a more medium-term but clean solution would be to integrate > one of these libs in GDB: > > https://github.com/Neargye/magic_enum > https://github.com/quicknir/wise_enum > > I use the latter in another project, and it works nicely. > > Otherwise, LGTM: > > Approved-By: Simon Marchi Can I add the tag with that change? (just making sure you're ok with my solution (: ) -- Cheers, Guinevere Larsen She/Her/Hers > > Simon >