From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by sourceware.org (Postfix) with ESMTPS id 054383849AC1 for ; Tue, 7 May 2024 23:44:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 054383849AC1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 054383849AC1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125459; cv=none; b=B3Nwj/1X3eTQI+++oHdnDfn2nvbOSAuQtXRTeTJzAZsycb5+DrsPcaRo/yg9xMJjzADmOj9kRbANP95njwsu0sc16dOTcDXTjLj3dQzTdd1lgv77vaA1TKjPKvyQeQOBsY1Wb7N/3D5kMFZ+g4dLpXRUFwZG3UPvUDZT+ytFzIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125459; c=relaxed/simple; bh=WQyNtAmKQcXhejdawclVE3vJIhdDOe+8CnrTSNcluCU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=oFnFVLL1kdp4xZWW2aCIeSJu18Ou/IuYlGFjGm7LYG6s2yhBdkbGvRhWO5FLCv/hSdZjNsPIWcQajWzIC2zOSiEf3kTQoRlJIo0ZHr0/ADjSTcArBP7WVkBpeOK/Y8mOYzMJqWlw97Si6Qc37iJDr30fjvWlm7GMOaEWx/ttx1k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41b5dd5af48so29868415e9.0 for ; Tue, 07 May 2024 16:44:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125457; x=1715730257; 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=sGibESpDX6Ost1X3ZF4xqXSGbf704PewkxCDSWGRBpA=; b=hYDWaXSbYJJCH/9euOMsoFUXE+Y/tSFse20IJbcgmI9yAODz9ixMsph2Zx2Hubygfg /9K5fDgsynCxhJ7mVnV94XE3dD3UAmlT3kM58JNbSq9ALlex9exDzAMMfBa9unioETJA mKQxwz53aXcNrnI0KY6P13APW4OwOoQtfoDWXfUTybzkpwB0NLlaSDVOflfO1MJDCU5r dCeWyXkhyfvG3mFl+M90gTw+VZ7Rkeqkyw/53FtPR1ETqp7IngnTOw3xXIw1AhA+kh4x l5Mlb9kajdL9E78nnjMCmD2dsv4tPEO/YEbTg++DNYNI4EoGa8BFdPPsBamhO9QcfDnv rPog== X-Gm-Message-State: AOJu0Yzj3cJyaGc/MwnHp1PQMEp3wSObwtq3BC+KaNRNFT7GQkshRMXJ RVKNcCfl8yiewX52O00tKZrUJHqSeAVZTrd9bsbnVjEn5oLMHhrt79yghOYI X-Google-Smtp-Source: AGHT+IGa9DwHM0cbuCEUcpGTlWy/mJ0m/moCdrAG/xUG2t6v0gl0duW4GNVDF8xmLEq6jIriDHYdIg== X-Received: by 2002:a05:600c:4f56:b0:41a:a5ff:ea3a with SMTP id 5b1f17b1804b1-41f714f6eb3mr8857075e9.19.1715125456663; Tue, 07 May 2024 16:44:16 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id i15-20020a05600c354f00b004186eb69a55sm197648wmq.25.2024.05.07.16.44.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:44:16 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 25/34] Windows gdb+gdbserver: Share $_siginfo reading code Date: Wed, 8 May 2024 00:42:24 +0100 Message-ID: <20240507234233.371123-26-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240507234233.371123-1-pedro@palves.net> References: <20240507234233.371123-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: Both GDB and GDBserver have similar code to read the $_siginfo data. This patch moves the bulk of it to gdb/nat/windows-nat.c so it can be shared. Change-Id: I47fc0d3323be5b6f6fcfe912b768051a41910666 --- gdb/nat/windows-nat.c | 49 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 9 ++++++++ gdb/windows-nat.c | 40 +++------------------------------- gdbserver/win32-low.cc | 42 ++++-------------------------------- 4 files changed, 65 insertions(+), 75 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index d43d549cb0d..4fd717e6521 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -153,6 +153,55 @@ windows_thread_info::thread_name () return name.get (); } +/* Read Windows signal info. See nat/windows-nat.h. */ + +bool +windows_thread_info::xfer_siginfo (gdb_byte *readbuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) +{ + if (last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) + return false; + + if (readbuf == nullptr) + return false; + + EXCEPTION_RECORD &er = last_event.u.Exception.ExceptionRecord; + + char *buf = (char *) &er; + size_t bufsize = sizeof (er); + +#ifdef __x86_64__ + EXCEPTION_RECORD32 er32; + if (proc->wow64_process) + { + buf = (char *) &er32; + bufsize = sizeof (er32); + + er32.ExceptionCode = er.ExceptionCode; + er32.ExceptionFlags = er.ExceptionFlags; + er32.ExceptionRecord + = (uintptr_t) er.ExceptionRecord; + er32.ExceptionAddress + = (uintptr_t) er.ExceptionAddress; + er32.NumberParameters = er.NumberParameters; + for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) + er32.ExceptionInformation[i] = er.ExceptionInformation[i]; + } +#endif + + if (offset > bufsize) + return false; + + if (offset + len > bufsize) + len = bufsize - offset; + + memcpy (readbuf, buf + offset, len); + *xfered_len = len; + + return true; +} + /* Try to determine the executable filename. EXE_NAME_RET is a pointer to a buffer whose size is EXE_NAME_MAX_LEN. diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 26b1eaea95a..af96811a2ba 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -70,6 +70,15 @@ struct windows_thread_info the next call. */ const char *thread_name (); + /* Read LEN bytes of the thread's $_siginfo into READBUF, starting + at OFFSET. Store the number of actually-read bytes in + XFERED_LEN. Returns true on success, false on failure. Passing + READBUF as NULL indicates that the caller is trying to write to + $_siginfo, which is a failure case. */ + bool xfer_siginfo (gdb_byte *readbuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len); + /* The process this thread belongs to. */ windows_process_info *proc; diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 0e77614b4f4..cb35ff41771 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -3110,44 +3110,10 @@ windows_xfer_siginfo (gdb_byte *readbuf, ULONGEST offset, ULONGEST len, { windows_thread_info *th = windows_process.find_thread (inferior_ptid); - if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) - return TARGET_XFER_E_IO; - - EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord; - - char *buf = (char *) &er; - size_t bufsize = sizeof (er); - -#ifdef __x86_64__ - EXCEPTION_RECORD32 er32; - if (windows_process.wow64_process) - { - buf = (char *) &er32; - bufsize = sizeof (er32); - - er32.ExceptionCode = er.ExceptionCode; - er32.ExceptionFlags = er.ExceptionFlags; - er32.ExceptionRecord = (uintptr_t) er.ExceptionRecord; - er32.ExceptionAddress = (uintptr_t) er.ExceptionAddress; - er32.NumberParameters = er.NumberParameters; - for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) - er32.ExceptionInformation[i] = er.ExceptionInformation[i]; - } -#endif - - if (readbuf == nullptr) - return TARGET_XFER_E_IO; - - if (offset > bufsize) + if (th->xfer_siginfo (readbuf, offset, len, xfered_len)) + return TARGET_XFER_OK; + else return TARGET_XFER_E_IO; - - if (offset + len > bufsize) - len = bufsize - offset; - - memcpy (readbuf, buf + offset, len); - *xfered_len = len; - - return TARGET_XFER_OK; } enum target_xfer_status diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 985c6a0a0ed..4707acc4e94 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1308,45 +1308,11 @@ win32_process_target::qxfer_siginfo (const char *annex, windows_thread_info *th = windows_process.find_thread (current_thread_ptid ()); - if (th->last_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) - return -1; - - if (readbuf == nullptr) - return -1; - - EXCEPTION_RECORD &er = th->last_event.u.Exception.ExceptionRecord; - - char *buf = (char *) &er; - size_t bufsize = sizeof (er); - -#ifdef __x86_64__ - EXCEPTION_RECORD32 er32; - if (windows_process.wow64_process) - { - buf = (char *) &er32; - bufsize = sizeof (er32); - - er32.ExceptionCode = er.ExceptionCode; - er32.ExceptionFlags = er.ExceptionFlags; - er32.ExceptionRecord - = (uintptr_t) er.ExceptionRecord; - er32.ExceptionAddress - = (uintptr_t) er.ExceptionAddress; - er32.NumberParameters = er.NumberParameters; - for (int i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) - er32.ExceptionInformation[i] = er.ExceptionInformation[i]; - } -#endif - - if (offset > bufsize) + ULONGEST xfered_len; + if (th->xfer_siginfo (readbuf, offset, len, &xfered_len)) + return xfered_len; + else return -1; - - if (offset + len > bufsize) - len = bufsize - offset; - - memcpy (readbuf, buf + offset, len); - - return len; } bool -- 2.43.2