From: Matthieu Longo <matthieu.longo@arm.com>
To: <gdb-patches@sourceware.org>
Cc: Luis Machado <luis.machado@amd.com>,
Luis Machado <luis.machado.foss@gmail.com>,
Andrew Burgess <aburgess@redhat.com>,
"Matthieu Longo" <matthieu.longo@arm.com>
Subject: [PATCH v1 1/8] gdb/linux-tdep: use pid_t consistently for process IDs
Date: Fri, 3 Jul 2026 19:58:46 +0100 [thread overview]
Message-ID: <20260703185853.450440-2-matthieu.longo@arm.com> (raw)
In-Reply-To: <20260703185853.450440-1-matthieu.longo@arm.com>
Use `pid_t' consistently instead of a mix of `pid_t', `int', and `long'
when representing process IDs in gdb/linux-tdep.c.
Also change inferior::pid to `pid_t' so that the inferior's process ID
uses the appropriate type throughout GDB.
Finally, factor out path templates "/proc/%d/{maps,smaps}" into named
constants.
---
gdb/inferior.h | 2 +-
gdb/linux-tdep.c | 41 ++++++++++++++++++++---------------------
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 9c031035a23..dc71cbdb264 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -590,7 +590,7 @@ class inferior : public refcounted_object,
/* Actual target inferior id, usually, a process id. This matches
the ptid_t.pid member of threads of this inferior. */
- int pid = 0;
+ pid_t pid = 0;
/* True if the PID was actually faked by GDB. */
bool fake_pid_p = false;
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index d5b0e6e7011..9f8f9f1af5e 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -48,6 +48,9 @@
#include <algorithm>
+constexpr const char *PROC_PID_SMAPS = "/proc/%d/smaps";
+constexpr const char *PROC_PID_MAPS = "/proc/%d/maps";
+
/* This enum represents the values that the user can choose when
informing the Linux kernel about which memory mappings will be
dumped in a corefile. They are described in the file
@@ -842,9 +845,7 @@ static void
linux_info_proc (struct gdbarch *gdbarch, const char *args,
enum info_proc_what what)
{
- /* A long is used for pid instead of an int to avoid a loss of precision
- compiler warning from the output of strtoul. */
- long pid;
+ pid_t pid;
int cmdline_f = (what == IP_MINIMAL || what == IP_CMDLINE || what == IP_ALL);
int cwd_f = (what == IP_MINIMAL || what == IP_CWD || what == IP_ALL);
int environ_f = (what == IP_ENVIRON || what == IP_ALL);
@@ -876,10 +877,10 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
if (args && args[0])
error (_("Too many parameters: %s"), args);
- gdb_printf (_("process %ld\n"), pid);
+ gdb_printf (_("process %d\n"), pid);
if (cmdline_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/cmdline", pid);
gdb_byte *buffer;
LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer);
@@ -901,7 +902,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (cwd_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/cwd", pid);
std::optional<std::string> contents
= target_fileio_readlink (NULL, filename, &target_errno);
if (contents.has_value ())
@@ -911,7 +912,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (environ_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/environ", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/environ", pid);
gdb_byte *buffer;
LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer);
@@ -935,7 +936,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (exe_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/exe", pid);
std::optional<std::string> contents
= target_fileio_readlink (NULL, filename, &target_errno);
if (contents.has_value ())
@@ -945,7 +946,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (mappings_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/maps", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/maps", pid);
gdb::unique_xmalloc_ptr<char> map
= target_fileio_read_stralloc (NULL, filename);
if (map != NULL)
@@ -990,7 +991,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (status_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/status", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/status", pid);
gdb::unique_xmalloc_ptr<char> status
= target_fileio_read_stralloc (NULL, filename);
if (status)
@@ -1000,7 +1001,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
if (stat_f)
{
- xsnprintf (filename, sizeof filename, "/proc/%ld/stat", pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/stat", pid);
gdb::unique_xmalloc_ptr<char> statstr
= target_fileio_read_stralloc (NULL, filename);
if (statstr)
@@ -1673,7 +1674,7 @@ linux_process_address_in_memtag_page (CORE_ADDR address)
pid_t pid = current_inferior ()->pid;
- std::string smaps_file = string_printf ("/proc/%d/smaps", pid);
+ std::string smaps_file = string_printf (PROC_PID_SMAPS, pid);
gdb::unique_xmalloc_ptr<char> data
= target_fileio_read_stralloc (NULL, smaps_file.c_str ());
@@ -1731,7 +1732,6 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
linux_dump_mapping_p_ftype *should_dump_mapping_p,
linux_find_memory_region_ftype func)
{
- pid_t pid;
/* Default dump behavior of coredump_filter (0x33), according to
Documentation/filesystems/proc.txt from the Linux kernel
tree. */
@@ -1744,7 +1744,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
if (current_inferior ()->fake_pid_p)
return false;
- pid = current_inferior ()->pid;
+ pid_t pid = current_inferior ()->pid;
if (use_coredump_filter)
{
@@ -1763,7 +1763,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
}
}
- std::string maps_filename = string_printf ("/proc/%d/smaps", pid);
+ std::string maps_filename = string_printf (PROC_PID_SMAPS, pid);
gdb::unique_xmalloc_ptr<char> data
= target_fileio_read_stralloc (NULL, maps_filename.c_str ());
@@ -1771,7 +1771,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
if (data == NULL)
{
/* Older Linux kernels did not support /proc/PID/smaps. */
- maps_filename = string_printf ("/proc/%d/maps", pid);
+ maps_filename = string_printf (PROC_PID_MAPS, pid);
data = target_fileio_read_stralloc (NULL, maps_filename.c_str ());
if (data == nullptr)
@@ -2805,7 +2805,6 @@ static bool
linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
{
char filename[100];
- long pid;
if (target_auxv_search (AT_SYSINFO_EHDR, &range->start) <= 0)
return false;
@@ -2844,7 +2843,7 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
if (current_inferior ()->fake_pid_p)
return false;
- pid = current_inferior ()->pid;
+ pid_t pid = current_inferior ()->pid;
/* Note that reading /proc/PID/task/PID/maps (1) is much faster than
reading /proc/PID/maps (2). The later identifies thread stacks
@@ -2854,7 +2853,7 @@ linux_vsyscall_range_raw (struct gdbarch *gdbarch, struct mem_range *range)
a few thousand threads, (1) takes a few milliseconds, while (2)
takes several seconds. Also note that "smaps", what we read for
determining core dump mappings, is even slower than "maps". */
- xsnprintf (filename, sizeof filename, "/proc/%ld/task/%ld/maps", pid, pid);
+ xsnprintf (filename, sizeof filename, "/proc/%d/task/%d/maps", pid, pid);
gdb::unique_xmalloc_ptr<char> data
= target_fileio_read_stralloc (NULL, filename);
if (data != NULL)
@@ -3168,9 +3167,9 @@ linux_address_in_shadow_stack_mem_range
if (!target_has_execution () || current_inferior ()->fake_pid_p)
return false;
- const int pid = current_inferior ()->pid;
+ pid_t pid = current_inferior ()->pid;
- std::string smaps_file = string_printf ("/proc/%d/smaps", pid);
+ std::string smaps_file = string_printf (PROC_PID_SMAPS, pid);
gdb::unique_xmalloc_ptr<char> data
= target_fileio_read_stralloc (nullptr, smaps_file.c_str ());
--
2.55.0
next prev parent reply other threads:[~2026-07-03 19:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 18:58 [PATCH v1 0/8] gdb: various refactoring in linux-tdep Matthieu Longo
2026-07-03 18:58 ` Matthieu Longo [this message]
2026-07-05 21:22 ` [PATCH v1 1/8] gdb/linux-tdep: use pid_t consistently for process IDs Tom Tromey
2026-07-06 9:30 ` Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 2/8] gdb/linux-tdep: change linux_fill_prpsinfo to return bool Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 3/8] target_fileio_read_stralloc: add an optional length parameter Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 4/8] gdb support: add index_type to array_view for documentation purpose Matthieu Longo
2026-07-03 19:55 ` Pedro Alves
2026-07-06 10:51 ` Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 5/8] gdb support: add gdb::replace algorithm for iterators and ranges Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 6/8] gdb: introduce helper class file_reader_t Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 7/8] gdb/linux-tdep: parse ProtectionKey in /proc/PID/smaps Matthieu Longo
2026-07-03 18:58 ` [PATCH v1 8/8] gdb/linux: add helpers to read AT_HWCAP3 Matthieu Longo
2026-07-07 10:39 ` Yury Khrustalev
2026-07-07 15:51 ` Matthieu Longo
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=20260703185853.450440-2-matthieu.longo@arm.com \
--to=matthieu.longo@arm.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado.foss@gmail.com \
--cc=luis.machado@amd.com \
/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