From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 48E253858D33 for ; Thu, 9 Mar 2023 14:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48E253858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12b.google.com with SMTP id x10so1116317ill.12 for ; Thu, 09 Mar 2023 06:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1678373531; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=898X2cJgbuXD/h1NSXYdoaJSOySn2KdERU3rrRT2tzU=; b=ip1mxelD+R866TGzlEJy7YzDVBuRHQ429IFEnqo63hoUtZvSq82P2HeoHaIqhUfF2l czvmpE97F42tzTSfugpRaZZN3VstPwZDtZbuMFW7wGq00VIElFnBcNrRGJNQzt5D+yWx GkJpjelaTNhXGACwsLOsu5kobkTzJ5gnQFI/HaiXs8SZGlHzneJZlWJpjZM7Kk/G6nU/ /1tT14cXNN3nC+UoS/gxLTRvAls9hbgrV/ZvKIW7OEu45RLdRNYwqIZnXSJpuVKMEl/O uMwI21Gqm/7XJw7Qn1i4rbiNBlWPsr+HJTKmXoCv0DM9ZVbjEjepcH/Y8c56zNVFsmPo Ln0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678373531; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=898X2cJgbuXD/h1NSXYdoaJSOySn2KdERU3rrRT2tzU=; b=fy4jokg6EZIiNbHRqarZiKvOnmOihxTUH43w+TDRiuraDLDS+FFYYpshVqilONgo9k 9U1Xn8sxmEp9Ura7qn777XVaYQoiq/8AHiifbJB5D5iinGus2giFTmJFpvVQ6Cz5vKDl AiK2bGZggv6RhG0CQouwd7Mr0V0I+9I0MzHKtas6VsKJRjUEd0LEl8MY4cNkUZOfnGNM 1rllSeh6ZXYJLg9Qziz885210X6FHOWiEDJhjZwSH/7Ru5WA9U/eZ2iCjUdAI89N3y0Q 0vYD4QHaC8OdSjUVu5cRwhrO1ZuOXA53p9GUEyfs4vaEag9ctTZx8uwGu47kfy90hzLW IbYg== X-Gm-Message-State: AO0yUKUy2s6hjy1MT//x3/R5H36oMCu6UI1T2KJ0XwkqbtZgVBjavQUA nr8gCbOXBnvWLaNLeDTvjIiS4A== X-Google-Smtp-Source: AK7set8vefoSTz3I0BYaFROoMfV7yCrfRLiTwsyzvvGclELeSfnrzNcLc8WLcKYTSp0Cquy8AQOOvg== X-Received: by 2002:a05:6e02:2162:b0:319:ac45:56f4 with SMTP id s2-20020a056e02216200b00319ac4556f4mr18129385ilv.7.1678373531391; Thu, 09 Mar 2023 06:52:11 -0800 (PST) Received: from murgatroyd (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id e17-20020a02a511000000b003c4eb5cb22csm5767387jam.134.2023.03.09.06.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 06:52:11 -0800 (PST) From: Tom Tromey To: Tom de Vries Cc: Tom Tromey , Tom Tromey via Gdb-patches Subject: Re: [PATCH] Fix DAP stackTrace through frames without debuginfo References: <20230215194847.3805619-1-tromey@adacore.com> <874jqx7vux.fsf@tromey.com> X-Attribution: Tom Date: Thu, 09 Mar 2023 07:52:10 -0700 In-Reply-To: (Tom de Vries's message of "Thu, 9 Mar 2023 09:38:54 +0100") Message-ID: <87fsaenfj9.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: Tom> I'm getting: Tom> ... Tom> {"request_seq": 5, "type": "response", "command": "stackTrace", Tom> "success": false, "message": "unhashable type: 'gdb.Frame'", "seq": Tom> 11}FAIL: gdb.dap/bt-nodebug.exp: backtrace success Tom> ... Tom> This is with python 3.6m. Can you try the appended? Tom commit cc1fbba7d9027927db2af10724c276e1e7c5ad7e Author: Tom Tromey Date: Thu Mar 9 07:47:29 2023 -0700 Implement hash function for gdb.Frame Tom de Vries pointed out that one DAP test failed on Python 3.6 because gdb.Frame is not hashable. This patch adds a hash function to gdb.Frame. diff --git a/gdb/frame-id.h b/gdb/frame-id.h index 8ddf7d11408..53abbe203bf 100644 --- a/gdb/frame-id.h +++ b/gdb/frame-id.h @@ -112,6 +112,9 @@ struct frame_id /* Return a string representation of this frame id. */ std::string to_string () const; + /* A hash function for this frame_id. */ + hashval_t hash () const; + /* Returns true when this frame_id and R identify the same frame. */ bool operator== (const frame_id &r) const; diff --git a/gdb/frame.c b/gdb/frame.c index 9b867b6cd9c..478bd881b63 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -228,26 +228,12 @@ frame_addr_hash (const void *ap) { const frame_info *frame = (const frame_info *) ap; const struct frame_id f_id = frame->this_id.value; - hashval_t hash = 0; gdb_assert (f_id.stack_status != FID_STACK_INVALID || f_id.code_addr_p || f_id.special_addr_p); - if (f_id.stack_status == FID_STACK_VALID) - hash = iterative_hash (&f_id.stack_addr, - sizeof (f_id.stack_addr), hash); - if (f_id.code_addr_p) - hash = iterative_hash (&f_id.code_addr, - sizeof (f_id.code_addr), hash); - if (f_id.special_addr_p) - hash = iterative_hash (&f_id.special_addr, - sizeof (f_id.special_addr), hash); - - char user_created_p = f_id.user_created_p; - hash = iterative_hash (&user_created_p, sizeof (user_created_p), hash); - - return hash; + return f_id.hash (); } /* Internal equality function for the hash table. This function @@ -796,6 +782,29 @@ frame_id_artificial_p (frame_id l) return l.artificial_depth != 0; } +/* See frame-id.h. */ + +hashval_t +frame_id::hash () const +{ + hashval_t hash = 0; + + if (stack_status == FID_STACK_VALID) + hash = iterative_hash (&stack_addr, + sizeof (stack_addr), hash); + if (code_addr_p) + hash = iterative_hash (&code_addr, + sizeof (code_addr), hash); + if (special_addr_p) + hash = iterative_hash (&special_addr, + sizeof (special_addr), hash); + + char user_created_p = user_created_p; + hash = iterative_hash (&user_created_p, sizeof (user_created_p), hash); + + return hash; +} + bool frame_id::operator== (const frame_id &r) const { diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index ecd55d2e568..099f39ac44e 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -687,6 +687,23 @@ gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args) return PyUnicode_Decode (str, strlen (str), host_charset (), NULL); } +/* Implement the hash method. */ + +static Py_hash_t +frapy_hash (PyObject *self) +{ + frame_object *self_frame = (frame_object *) self; + + hashval_t hash = self_frame->frame_id.hash (); + hash <<= 1; + hash |= self_frame->frame_id_is_next; + + Py_hash_t result = (Py_hash_t) hash; + if (result == -1) + result = 0; + return result; +} + /* Implements the equality comparison for Frame objects. All other comparison operators will throw a TypeError Python exception, as they aren't valid for frames. */ @@ -816,7 +833,7 @@ PyTypeObject frame_object_type = { 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + frapy_hash, /* tp_hash */ 0, /* tp_call */ frapy_str, /* tp_str */ 0, /* tp_getattro */