public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "fredrik.hederstierna@securitas-direct.com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug remote/25111] [Zephyr/thread aware debugging] remote: write_ptid returns negative tid.
Date: Sun, 07 Nov 2021 08:04:16 +0000	[thread overview]
Message-ID: <bug-25111-4717-jw3sC2DiSJ@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-25111-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=25111

Fredrik Hederstierna <fredrik.hederstierna@securitas-direct.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fredrik.hederstierna@securi
                   |                            |tas-direct.com

--- Comment #1 from Fredrik Hederstierna <fredrik.hederstierna@securitas-direct.com> ---
When looking into Zephyr and OpenOCD I just saw this ticket. Isn't there a
discrepancy in <gdb/remote.c> for ptid_t write/read when it comes to types. The
'lwp' is used as 'tid', but has a wider type:

  int   ptid_get_pid (ptid_t ptid)
  long  ptid_get_lwp (ptid_t ptid)
  long  ptid_get_tid (ptid_t ptid)

so in the <read_ptid> it reads into ULONGEST, which I guess is uint64_t, but
the <write_tpid> instead implicit cast long to int when using 'lwp as 'tid'
(which I believe is often int32_t on a normal host target machine):

  int tid;
  tid = ptid.lwp ();

Wouldn't it be better to keep the wider long type, and keep calling 'tid' for
'lwp' which it actually is? And also keeping the long-type in the write
function? In this case there won't be any overflow if an 32bit int representing
'tid' is becoming >0x80000000. The read function I guess will still handle it
as it is using ULONGEST to my understanding.

Attaching idea of a possible patch.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

       reply	other threads:[~2021-11-07  8:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-25111-4717@http.sourceware.org/bugzilla/>
2021-11-07  8:04 ` fredrik.hederstierna@securitas-direct.com [this message]
2021-11-07  8:06 ` fredrik.hederstierna@securitas-direct.com
2021-11-07 12:44 ` simark at simark dot ca
2022-01-07 21:11 ` tromey at sourceware dot org
2022-01-07 21:11 ` tromey at sourceware dot org
2023-08-03 17:07 ` tromey at sourceware dot org
2023-08-04  7:32 ` fredrik.hederstierna@securitas-direct.com
2024-02-15 16:59 ` tromey at sourceware dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-25111-4717-jw3sC2DiSJ@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).