[PATCH v2] Enhance "net" command to display IPv6 address of network interface
by Lianbo Jiang
Currently, the "net" command displays only the IPv4 address of a network
interface, it doesn't support outputting IPv6 address yet. For example:
Without the patch:
crash> net
NET_DEVICE NAME IP ADDRESS(ES)
ffff8d01b1205000 lo 127.0.0.1
ffff8d0087e40000 eno1 192.168.122.2
With the patch:
crash> net
NET_DEVICE NAME IP ADDRESS(ES) INET6 ADDRESS
ffff8d01b1205000 lo 127.0.0.1 ::1
ffff8d0087e40000 eno1 192.168.122.2 xxxx:xx:x:xxxx:xxxx:xxx:xxxx:xxxx, yyyy::yyyy:yyy:yyyy:yyyy
Related kernel commit:
502a2ffd7376 ("ipv6: convert idev_list to list macros")
Reported-by: Buland Kumar Singh <bsingh(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
defs.h | 6 +++
net.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++---
symbols.c | 12 ++++++
3 files changed, 135 insertions(+), 6 deletions(-)
diff --git a/defs.h b/defs.h
index e76af3c78b69..1f2cf6e0ce01 100644
--- a/defs.h
+++ b/defs.h
@@ -2208,6 +2208,12 @@ struct offset_table { /* stash of commonly-used offsets */
long sock_common_skc_v6_daddr;
long sock_common_skc_v6_rcv_saddr;
long inactive_task_frame_bp;
+ long net_device_ip6_ptr;
+ long inet6_dev_addr_list;
+ long inet6_ifaddr_addr;
+ long inet6_ifaddr_if_list;
+ long inet6_ifaddr_if_next;
+ long in6_addr_in6_u;
};
struct size_table { /* stash of commonly-used sizes */
diff --git a/net.c b/net.c
index aa445ab7ee13..52336762c85c 100644
--- a/net.c
+++ b/net.c
@@ -41,6 +41,7 @@ struct net_table {
long in_ifaddr_ifa_next;
long in_ifaddr_ifa_address;
int net_device_name_index;
+ long dev_ip6_ptr;
} net_table = { 0 };
struct net_table *net = &net_table;
@@ -71,6 +72,7 @@ static void print_neighbour_q(ulong, int);
static void get_netdev_info(ulong, struct devinfo *);
static void get_device_name(ulong, char *);
static long get_device_address(ulong, char **, long);
+static void get_device_ip6_address(ulong, char **, long);
static void get_sock_info(ulong, char *);
static void dump_arp(void);
static void arp_state_to_flags(unsigned char);
@@ -114,6 +116,13 @@ net_init(void)
net->dev_ip_ptr = MEMBER_OFFSET_INIT(net_device_ip_ptr,
"net_device", "ip_ptr");
MEMBER_OFFSET_INIT(net_device_dev_list, "net_device", "dev_list");
+ net->dev_ip6_ptr = MEMBER_OFFSET_INIT(net_device_ip6_ptr, "net_device", "ip6_ptr");
+ MEMBER_OFFSET_INIT(inet6_dev_addr_list, "inet6_dev", "addr_list");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_addr, "inet6_ifaddr", "addr");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_if_list, "inet6_ifaddr", "if_list");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_if_next, "inet6_ifaddr", "if_next");
+ MEMBER_OFFSET_INIT(in6_addr_in6_u, "in6_addr", "in6_u");
+
MEMBER_OFFSET_INIT(net_dev_base_head, "net", "dev_base_head");
ARRAY_LENGTH_INIT(net->net_device_name_index,
net_device_name, "net_device.name", NULL, sizeof(char));
@@ -466,7 +475,7 @@ show_net_devices(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -477,7 +486,14 @@ show_net_devices(ulong task)
get_device_name(next, buf);
fprintf(fp, "%-6s ", buf);
- buflen = get_device_address(next, &buf, buflen);
+ get_device_address(next, &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(next, &buf, buflen);
fprintf(fp, "%s\n", buf);
readmem(next+net->dev_next, KVADDR, &next,
@@ -503,7 +519,7 @@ show_net_devices_v2(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -530,7 +546,14 @@ show_net_devices_v2(ulong task)
get_device_name(ld->list_ptr[i], buf);
fprintf(fp, "%-6s ", buf);
- buflen = get_device_address(ld->list_ptr[i], &buf, buflen);
+ get_device_address(ld->list_ptr[i], &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(ld->list_ptr[i], &buf, buflen);
fprintf(fp, "%s\n", buf);
}
@@ -556,7 +579,7 @@ show_net_devices_v3(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -593,7 +616,14 @@ show_net_devices_v3(ulong task)
get_device_name(ld->list_ptr[i], buf);
fprintf(fp, "%-6s ", buf);
- buflen = get_device_address(ld->list_ptr[i], &buf, buflen);
+ get_device_address(ld->list_ptr[i], &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(ld->list_ptr[i], &buf, buflen);
fprintf(fp, "%s\n", buf);
}
@@ -925,6 +955,87 @@ get_device_address(ulong devaddr, char **bufp, long buflen)
return buflen;
}
+static void
+get_device_ip6_address(ulong devaddr, char **bufp, long buflen)
+{
+ ulong ip6_ptr = 0, i, cnt = 0, pos = 0, bufsize = buflen;
+ struct list_data list_data, *ld;
+ struct in6_addr ip6_addr;
+ char *buf;
+ char str[INET6_ADDRSTRLEN + 1] = {0};
+ char buffer[INET6_ADDRSTRLEN + 4] = {0};
+ uint len = 0;
+
+ buf = *bufp;
+ BZERO(buf, buflen);
+
+ readmem(devaddr + net->dev_ip6_ptr, KVADDR,
+ &ip6_ptr, sizeof(ulong), "ip6_ptr", FAULT_ON_ERROR);
+
+ if (!ip6_ptr)
+ return;
+
+ if (MEMBER_TYPE("inet6_dev", "addr_list") == TYPE_CODE_PTR) {
+ ulong addrp = 0;
+ /*
+ * 502a2ffd7376 ("ipv6: convert idev_list to list macros")
+ * v2.6.35-rc1~473^2~733
+ */
+ readmem(ip6_ptr + OFFSET(inet6_dev_addr_list), KVADDR,
+ &addrp, sizeof(void *), "addr_list", FAULT_ON_ERROR);
+
+ while (addrp) {
+ readmem(addrp + OFFSET(in6_addr_in6_u), KVADDR, &ip6_addr,
+ sizeof(struct in6_addr), "in6_addr.in6_u", FAULT_ON_ERROR);
+ inet_ntop(AF_INET6, (void*)&ip6_addr, str, INET6_ADDRSTRLEN);
+ sprintf(buffer, "%s%s", pos ? ", " : "", str);
+ len = strlen(buffer);
+
+ if (pos + len >= bufsize) {
+ RESIZEBUF(*bufp, bufsize, bufsize + buflen);
+ buf = *bufp;
+ BZERO(buf + bufsize, buflen);
+ bufsize += buflen;
+ }
+ BCOPY(buffer, &buf[pos], len);
+ pos += len;
+ readmem(addrp + OFFSET(inet6_ifaddr_if_next), KVADDR, &addrp,
+ sizeof(void *), "inet6_ifaddr.if_next", FAULT_ON_ERROR);
+ }
+
+ return;
+ }
+
+ ld = &list_data;
+ BZERO(ld, sizeof(struct list_data));
+ ld->flags |= LIST_ALLOCATE;
+ ld->start = ip6_ptr + OFFSET(inet6_dev_addr_list);
+ cnt = do_list(ld);
+
+ for (i = 1; i < cnt; i++) {
+ ulong addr;
+
+ addr = ld->list_ptr[i] + OFFSET(inet6_ifaddr_addr);
+ addr -= OFFSET(inet6_ifaddr_if_list);
+ readmem(addr + OFFSET(in6_addr_in6_u), KVADDR, &ip6_addr,
+ sizeof(struct in6_addr), "in6_addr.in6_u", FAULT_ON_ERROR);
+
+ inet_ntop(AF_INET6, (void*)&ip6_addr, str, INET6_ADDRSTRLEN);
+ sprintf(buffer, "%s%s", pos ? ", " : "", str);
+ len = strlen(buffer);
+
+ if (pos + len >= bufsize) {
+ RESIZEBUF(*bufp, bufsize, bufsize + buflen);
+ buf = *bufp;
+ BZERO(buf + bufsize, buflen);
+ bufsize += buflen;
+ }
+ BCOPY(buffer, &buf[pos], len);
+ pos += len;
+ }
+
+ FREEBUF(ld->list_ptr);
+}
/*
* Get the family, type, local and destination address/port pairs.
*/
diff --git a/symbols.c b/symbols.c
index a974fc9141a0..c8bdeb841cdc 100644
--- a/symbols.c
+++ b/symbols.c
@@ -9787,6 +9787,18 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(net_device_addr_len));
fprintf(fp, " net_device_ip_ptr: %ld\n",
OFFSET(net_device_ip_ptr));
+ fprintf(fp, " net_device_ip6_ptr: %ld\n",
+ OFFSET(net_device_ip6_ptr));
+ fprintf(fp, " inet6_dev_addr_list: %ld\n",
+ OFFSET(inet6_dev_addr_list));
+ fprintf(fp, " inet6_ifaddr_addr: %ld\n",
+ OFFSET(inet6_ifaddr_addr));
+ fprintf(fp, " inet6_ifaddr_if_list: %ld\n",
+ OFFSET(inet6_ifaddr_if_list));
+ fprintf(fp, " inet6_ifaddr_if_next: %ld\n",
+ OFFSET(inet6_ifaddr_if_next));
+ fprintf(fp, " in6_addr_in6_u: %ld\n",
+ OFFSET(in6_addr_in6_u));
fprintf(fp, " net_device_dev_list: %ld\n",
OFFSET(net_device_dev_list));
fprintf(fp, " net_dev_base_head: %ld\n",
--
2.37.1
1 year, 6 months
[PATCH] Fix for "search" command failing in maple tree kernel
by Tao Liu
Kernel with maple tree enabled doesn't have mmap as a member of mm_struct[1],
so OFFSET(mm_struct_mmap) case needed to be handled differently for
maple tree kernel.
Before:
crash> search -u a
search: invalid structure member offset: mm_struct_mmap
FILE: memory.c LINE: 14255 FUNCTION: address_space_start()
[crash] error trace: 549500 => 548fff => 5f1c91 => 5f1c13
5f1c13: OFFSET_verify.part.36+51
5f1c91: OFFSET_verify+49
548fff: address_space_start+106
549500: cmd_search+855
search: invalid structure member offset: mm_struct_mmap
FILE: memory.c LINE: 14255 FUNCTION: address_space_start()
After:
crash> search -u a
7ffea63e6440: a
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit...
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
memory.c | 87 ++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 65 insertions(+), 22 deletions(-)
diff --git a/memory.c b/memory.c
index d9cd616..63ea9f4 100644
--- a/memory.c
+++ b/memory.c
@@ -14245,14 +14245,28 @@ vaddr_type(ulong vaddr, struct task_context *tc)
static int
address_space_start(struct task_context *tc, ulong *addr)
{
- ulong vma;
+ ulong mm_mt, entry_num, i, vma = 0;
char *vma_buf;
+ struct list_pair *entry_list;
if (!tc->mm_struct)
return FALSE;
- fill_mm_struct(tc->mm_struct);
- vma = ULONG(tt->mm_struct + OFFSET(mm_struct_mmap));
+ if (INVALID_MEMBER(mm_struct_mmap) && VALID_MEMBER(mm_struct_mm_mt)) {
+ mm_mt = tc->mm_struct + OFFSET(mm_struct_mm_mt);
+ entry_num = do_maple_tree(mm_mt, MAPLE_TREE_COUNT, NULL);
+ entry_list = (struct list_pair *)GETBUF(entry_num * sizeof(struct list_pair));
+ do_maple_tree(mm_mt, MAPLE_TREE_GATHER, entry_list);
+ for (i = 0; i < entry_num; i++) {
+ if (!!(vma = (ulong)entry_list[i].value))
+ break;
+ }
+ FREEBUF(entry_list);
+ } else {
+ fill_mm_struct(tc->mm_struct);
+ vma = ULONG(tt->mm_struct + OFFSET(mm_struct_mmap));
+ }
+
if (!vma)
return FALSE;
vma_buf = fill_vma_cache(vma);
@@ -15491,6 +15505,30 @@ search_physical(struct searchinfo *si)
FREEBUF(pagebuf);
}
+static bool
+check_vma(ulong vma, ulong vaddr, ulong *vm_next, ulong *nextvaddr)
+{
+ char *vma_buf;
+ ulong vm_start, vm_end;
+
+ vma_buf = fill_vma_cache(vma);
+
+ vm_start = ULONG(vma_buf + OFFSET(vm_area_struct_vm_start));
+ vm_end = ULONG(vma_buf + OFFSET(vm_area_struct_vm_end));
+ if (vm_next)
+ *vm_next = ULONG(vma_buf + OFFSET(vm_area_struct_vm_next));
+
+ if (vaddr <= vm_start) {
+ *nextvaddr = vm_start;
+ return TRUE;
+ }
+
+ if ((vaddr > vm_start) && (vaddr < vm_end)) {
+ *nextvaddr = vaddr;
+ return TRUE;
+ }
+ return FALSE;
+}
/*
* Return the next mapped user virtual address page that comes after
@@ -15503,34 +15541,39 @@ next_upage(struct task_context *tc, ulong vaddr, ulong *nextvaddr)
char *vma_buf;
ulong vm_start, vm_end;
ulong vm_next;
+ ulong mm_mt, entry_num, i;
+ struct list_pair *entry_list;
if (!tc->mm_struct)
return FALSE;
- fill_mm_struct(tc->mm_struct);
- vma = ULONG(tt->mm_struct + OFFSET(mm_struct_mmap));
+ fill_mm_struct(tc->mm_struct);
+ vaddr = VIRTPAGEBASE(vaddr) + PAGESIZE(); /* first possible page */
total_vm = ULONG(tt->mm_struct + OFFSET(mm_struct_total_vm));
-
- if (!vma || (total_vm == 0))
+ if (!total_vm)
return FALSE;
- vaddr = VIRTPAGEBASE(vaddr) + PAGESIZE(); /* first possible page */
-
- for ( ; vma; vma = vm_next) {
- vma_buf = fill_vma_cache(vma);
-
- vm_start = ULONG(vma_buf + OFFSET(vm_area_struct_vm_start));
- vm_end = ULONG(vma_buf + OFFSET(vm_area_struct_vm_end));
- vm_next = ULONG(vma_buf + OFFSET(vm_area_struct_vm_next));
-
- if (vaddr <= vm_start) {
- *nextvaddr = vm_start;
- return TRUE;
+ if (INVALID_MEMBER(mm_struct_mmap) && VALID_MEMBER(mm_struct_mm_mt)) {
+ mm_mt = tc->mm_struct + OFFSET(mm_struct_mm_mt);
+ entry_num = do_maple_tree(mm_mt, MAPLE_TREE_COUNT, NULL);
+ entry_list = (struct list_pair *)GETBUF(entry_num * sizeof(struct list_pair));
+ do_maple_tree(mm_mt, MAPLE_TREE_GATHER, entry_list);
+ for (i = 0; i < entry_num; i++) {
+ if (!!(vma = (ulong)entry_list[i].value) &&
+ check_vma(vma, vaddr, NULL, nextvaddr)) {
+ FREEBUF(entry_list);
+ return TRUE;
+ }
}
+ FREEBUF(entry_list);
+ } else {
+ vma = ULONG(tt->mm_struct + OFFSET(mm_struct_mmap));
- if ((vaddr > vm_start) && (vaddr < vm_end)) {
- *nextvaddr = vaddr;
- return TRUE;
+ if (!vma)
+ return FALSE;
+ for ( ; vma; vma = vm_next) {
+ if (check_vma(vma, vaddr, &vm_next, nextvaddr))
+ return TRUE;
}
}
--
2.33.1
1 year, 6 months
[PATCH] Enhance "net" command to display IPv6 address of network interface
by Lianbo Jiang
Currently, the "net" command displays only the IPv4 address of a network
interface, it doesn't support outputting IPv6 address yet. For example:
Without the patch:
crash> net
NET_DEVICE NAME IP ADDRESS(ES)
ffff8d01b1205000 lo 127.0.0.1
ffff8d0087e40000 eno1 192.168.122.2
With the patch:
crash> net
NET_DEVICE NAME IP ADDRESS(ES) INET6 ADDRESS
ffff8d01b1205000 lo 127.0.0.1 ::1
ffff8d0087e40000 eno1 192.168.122.2 xxxx:xx:x:xxxx:xxxx:xxx:xxxx:xxxx, yyyy::yyyy:yyy:yyyy:yyyy
Related kernel commit:
502a2ffd7376 ("ipv6: convert idev_list to list macros")
Reported-by: Buland Kumar Singh <bsingh(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
defs.h | 6 +++
net.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
symbols.c | 12 ++++++
3 files changed, 133 insertions(+), 4 deletions(-)
diff --git a/defs.h b/defs.h
index e76af3c78b69..1f2cf6e0ce01 100644
--- a/defs.h
+++ b/defs.h
@@ -2208,6 +2208,12 @@ struct offset_table { /* stash of commonly-used offsets */
long sock_common_skc_v6_daddr;
long sock_common_skc_v6_rcv_saddr;
long inactive_task_frame_bp;
+ long net_device_ip6_ptr;
+ long inet6_dev_addr_list;
+ long inet6_ifaddr_addr;
+ long inet6_ifaddr_if_list;
+ long inet6_ifaddr_if_next;
+ long in6_addr_in6_u;
};
struct size_table { /* stash of commonly-used sizes */
diff --git a/net.c b/net.c
index aa445ab7ee13..5da2042d83ad 100644
--- a/net.c
+++ b/net.c
@@ -41,6 +41,7 @@ struct net_table {
long in_ifaddr_ifa_next;
long in_ifaddr_ifa_address;
int net_device_name_index;
+ long dev_ip6_ptr;
} net_table = { 0 };
struct net_table *net = &net_table;
@@ -71,6 +72,7 @@ static void print_neighbour_q(ulong, int);
static void get_netdev_info(ulong, struct devinfo *);
static void get_device_name(ulong, char *);
static long get_device_address(ulong, char **, long);
+static void get_device_ip6_address(ulong, char **, long);
static void get_sock_info(ulong, char *);
static void dump_arp(void);
static void arp_state_to_flags(unsigned char);
@@ -114,6 +116,13 @@ net_init(void)
net->dev_ip_ptr = MEMBER_OFFSET_INIT(net_device_ip_ptr,
"net_device", "ip_ptr");
MEMBER_OFFSET_INIT(net_device_dev_list, "net_device", "dev_list");
+ net->dev_ip6_ptr = MEMBER_OFFSET_INIT(net_device_ip6_ptr, "net_device", "ip6_ptr");
+ MEMBER_OFFSET_INIT(inet6_dev_addr_list, "inet6_dev", "addr_list");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_addr, "inet6_ifaddr", "addr");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_if_list, "inet6_ifaddr", "if_list");
+ MEMBER_OFFSET_INIT(inet6_ifaddr_if_next, "inet6_ifaddr", "if_next");
+ MEMBER_OFFSET_INIT(in6_addr_in6_u, "in6_addr", "in6_u");
+
MEMBER_OFFSET_INIT(net_dev_base_head, "net", "dev_base_head");
ARRAY_LENGTH_INIT(net->net_device_name_index,
net_device_name, "net_device.name", NULL, sizeof(char));
@@ -466,7 +475,7 @@ show_net_devices(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -478,6 +487,13 @@ show_net_devices(ulong task)
fprintf(fp, "%-6s ", buf);
buflen = get_device_address(next, &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(next, &buf, buflen);
fprintf(fp, "%s\n", buf);
readmem(next+net->dev_next, KVADDR, &next,
@@ -503,7 +519,7 @@ show_net_devices_v2(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -531,6 +547,13 @@ show_net_devices_v2(ulong task)
fprintf(fp, "%-6s ", buf);
buflen = get_device_address(ld->list_ptr[i], &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(ld->list_ptr[i], &buf, buflen);
fprintf(fp, "%s\n", buf);
}
@@ -556,7 +579,7 @@ show_net_devices_v3(ulong task)
buf = GETBUF(buflen);
flen = MAX(VADDR_PRLEN, strlen(net->netdevice));
- fprintf(fp, "%s NAME IP ADDRESS(ES)\n",
+ fprintf(fp, "%s NAME IP ADDRESS(ES) INET6 ADDRESS\n",
mkstring(upper_case(net->netdevice, buf),
flen, CENTER|LJUST, NULL));
@@ -593,7 +616,14 @@ show_net_devices_v3(ulong task)
get_device_name(ld->list_ptr[i], buf);
fprintf(fp, "%-6s ", buf);
- buflen = get_device_address(ld->list_ptr[i], &buf, buflen);
+ get_device_address(ld->list_ptr[i], &buf, buflen);
+
+ if (strlen(buf) > 0)
+ fprintf(fp, "%-6s ", buf);
+ else
+ fprintf(fp, "\t\t");
+
+ get_device_ip6_address(ld->list_ptr[i], &buf, buflen);
fprintf(fp, "%s\n", buf);
}
@@ -925,6 +955,87 @@ get_device_address(ulong devaddr, char **bufp, long buflen)
return buflen;
}
+static void
+get_device_ip6_address(ulong devaddr, char **bufp, long buflen)
+{
+ ulong ip6_ptr = 0, i, cnt = 0, pos = 0, bufsize = buflen;
+ struct list_data list_data, *ld;
+ struct in6_addr ip6_addr;
+ char *buf;
+ char str[INET6_ADDRSTRLEN + 1] = {0};
+ char buffer[INET6_ADDRSTRLEN + 4] = {0};
+ uint len = 0;
+
+ buf = *bufp;
+ BZERO(buf, buflen);
+
+ readmem(devaddr + net->dev_ip6_ptr, KVADDR,
+ &ip6_ptr, sizeof(ulong), "ip6_ptr", FAULT_ON_ERROR);
+
+ if (!ip6_ptr)
+ return;
+
+ if (MEMBER_TYPE("inet6_dev", "addr_list") == TYPE_CODE_PTR) {
+ ulong addrp = 0;
+ /*
+ * 502a2ffd7376 ("ipv6: convert idev_list to list macros")
+ * v2.6.35-rc1~473^2~733
+ */
+ readmem(ip6_ptr + OFFSET(inet6_dev_addr_list), KVADDR,
+ &addrp, sizeof(void *), "addr_list", FAULT_ON_ERROR);
+
+ while (addrp) {
+ readmem(addrp + OFFSET(in6_addr_in6_u), KVADDR, &ip6_addr,
+ sizeof(struct in6_addr), "in6_addr.in6_u", FAULT_ON_ERROR);
+ inet_ntop(AF_INET6, (void*)&ip6_addr, str, INET6_ADDRSTRLEN);
+ sprintf(buffer, "%s%s", pos ? ", " : "", str);
+ len = strlen(buffer);
+
+ if (pos + len >= bufsize) {
+ RESIZEBUF(*bufp, bufsize, bufsize + buflen);
+ buf = *bufp;
+ BZERO(buf + bufsize, buflen);
+ bufsize += buflen;
+ }
+ BCOPY(buffer, &buf[pos], len);
+ pos += len;
+ readmem(addrp + OFFSET(inet6_ifaddr_if_next), KVADDR, &addrp,
+ sizeof(void *), "inet6_ifaddr.if_next", FAULT_ON_ERROR);
+ }
+
+ return;
+ }
+
+ ld = &list_data;
+ BZERO(ld, sizeof(struct list_data));
+ ld->flags |= LIST_ALLOCATE;
+ ld->start = ip6_ptr + OFFSET(inet6_dev_addr_list);
+ cnt = do_list(ld);
+
+ for (i = 1; i < cnt; i++) {
+ ulong addr;
+
+ addr = ld->list_ptr[i] + OFFSET(inet6_ifaddr_addr);
+ addr -= OFFSET(inet6_ifaddr_if_list);
+ readmem(addr + OFFSET(in6_addr_in6_u), KVADDR, &ip6_addr,
+ sizeof(struct in6_addr), "in6_addr.in6_u", FAULT_ON_ERROR);
+
+ inet_ntop(AF_INET6, (void*)&ip6_addr, str, INET6_ADDRSTRLEN);
+ sprintf(buffer, "%s%s", pos ? ", " : "", str);
+ len = strlen(buffer);
+
+ if (pos + len >= bufsize) {
+ RESIZEBUF(*bufp, bufsize, bufsize + buflen);
+ buf = *bufp;
+ BZERO(buf + bufsize, buflen);
+ bufsize += buflen;
+ }
+ BCOPY(buffer, &buf[pos], len);
+ pos += len;
+ }
+
+ FREEBUF(ld->list_ptr);
+}
/*
* Get the family, type, local and destination address/port pairs.
*/
diff --git a/symbols.c b/symbols.c
index a974fc9141a0..c8bdeb841cdc 100644
--- a/symbols.c
+++ b/symbols.c
@@ -9787,6 +9787,18 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(net_device_addr_len));
fprintf(fp, " net_device_ip_ptr: %ld\n",
OFFSET(net_device_ip_ptr));
+ fprintf(fp, " net_device_ip6_ptr: %ld\n",
+ OFFSET(net_device_ip6_ptr));
+ fprintf(fp, " inet6_dev_addr_list: %ld\n",
+ OFFSET(inet6_dev_addr_list));
+ fprintf(fp, " inet6_ifaddr_addr: %ld\n",
+ OFFSET(inet6_ifaddr_addr));
+ fprintf(fp, " inet6_ifaddr_if_list: %ld\n",
+ OFFSET(inet6_ifaddr_if_list));
+ fprintf(fp, " inet6_ifaddr_if_next: %ld\n",
+ OFFSET(inet6_ifaddr_if_next));
+ fprintf(fp, " in6_addr_in6_u: %ld\n",
+ OFFSET(in6_addr_in6_u));
fprintf(fp, " net_device_dev_list: %ld\n",
OFFSET(net_device_dev_list));
fprintf(fp, " net_dev_base_head: %ld\n",
--
2.37.1
1 year, 6 months
[PATCH] Fix for "dis" command to correctly display the offset of disassembly code
by Lianbo Jiang
For gdb-10.2, the disassembly code may start with "=>", which needs to
be stripped when calculating the address. Otherwise, parsing the address
will fail because the current code always assumes that it starts with the
"0x". For example:
crash> gdb disassemble 0xffffffffa2317add
Dump of assembler code for function native_queued_spin_lock_slowpath:
0xffffffffa2317ab0 <+0>: nopl 0x0(%rax,%rax,1)
0xffffffffa2317ab5 <+5>: push %rbp
0xffffffffa2317ab6 <+6>: mov %rsp,%rbp
...
0xffffffffa2317ad3 <+35>: mov %edx,%eax
0xffffffffa2317ad5 <+37>: lock cmpxchg %ecx,(%rdi)
=> 0xffffffffa2317ad9 <+41>: cmp %eax,%edx
0xffffffffa2317adb <+43>: jne 0xffffffffa2317ac0 <native_queued_spin_lock_slowpath+16>
0xffffffffa2317add <+45>: pop %rbp
0xffffffffa2317ade <+46>: xchg %ax,%ax
...
Without the patch:
crash> dis 0xffffffffa2317add -r | tail -5
0xffffffffa2317ad3 <native_queued_spin_lock_slowpath+35>: mov %edx,%eax
0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>: lock cmpxchg %ecx,(%rdi)
0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>: cmp %eax,%edx
^^^
0xffffffffa2317adb <native_queued_spin_lock_slowpath+43>: jne 0xffffffffa2317ac0 <native_queued_spin_lock_slowpath+16>
0xffffffffa2317add <native_queued_spin_lock_slowpath+45>: pop %rbp
With the patch:
crash> dis 0xffffffffa2317add -r | tail -5
0xffffffffa2317ad3 <native_queued_spin_lock_slowpath+35>: mov %edx,%eax
0xffffffffa2317ad5 <native_queued_spin_lock_slowpath+37>: lock cmpxchg %ecx,(%rdi)
0xffffffffa2317ad9 <native_queued_spin_lock_slowpath+41>: cmp %eax,%edx
0xffffffffa2317adb <native_queued_spin_lock_slowpath+43>: jne 0xffffffffa2317ac0 <native_queued_spin_lock_slowpath+16>
0xffffffffa2317add <native_queued_spin_lock_slowpath+45>: pop %rbp
Reported-by: Vernon Lovejoy <vlovejoy(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
kernel.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel.c b/kernel.c
index a42e6ad7d78c..6e98f5f6f6b1 100644
--- a/kernel.c
+++ b/kernel.c
@@ -2112,6 +2112,10 @@ cmd_dis(void)
rewind(pc->tmpfile);
while (fgets(buf2, BUFSIZE, pc->tmpfile)) {
+
+ if (STRNEQ(buf2, "=>"))
+ shift_string_left(buf2, 2);
+
strip_beginning_whitespace(buf2);
if (do_load_module_filter)
--
2.37.1
1 year, 6 months
[PATCH] x86_64: Fix "bt" command on kernels with random_kstack_offset=on
by HAGIO KAZUHITO(萩尾 一仁)
On kernels configured with CONFIG_RANDOMIZE_KSTACK_OFFSET=y and
random_kstack_offset=on, a random offset is added to the stack with
__kstack_alloca() at the beginning of do_syscall_64() and other syscall
entry functions. This function has the following instruction.
<do_syscall_64+32>: sub %rax,%rsp
On the other hand, crash uses only a part of data for ORC unwinder to
unwind stacks and if an ip value doesn't have a usable ORC data, it
caluculates the frame size with parsing the assembly of the function.
However, crash cannot calculate the frame size correctly with the
instruction above, and prints stale return addresses like this:
crash> bt 1
PID: 1 TASK: ffff9c250023b880 CPU: 0 COMMAND: "systemd"
#0 [ffffb7e5c001fc80] __schedule at ffffffff91ae2b16
#1 [ffffb7e5c001fd00] schedule at ffffffff91ae2ed3
#2 [ffffb7e5c001fd18] schedule_hrtimeout_range_clock at ffffffff91ae7ed8
#3 [ffffb7e5c001fda8] ep_poll at ffffffff913ef828
#4 [ffffb7e5c001fe48] do_epoll_wait at ffffffff913ef943
#5 [ffffb7e5c001fe80] __x64_sys_epoll_wait at ffffffff913f0130
#6 [ffffb7e5c001fed0] do_syscall_64 at ffffffff91ad7169
#7 [ffffb7e5c001fef0] do_syscall_64 at ffffffff91ad7179 <<
#8 [ffffb7e5c001ff10] syscall_exit_to_user_mode at ffffffff91adaab2 << stale entries
#9 [ffffb7e5c001ff20] do_syscall_64 at ffffffff91ad7179 <<
#10 [ffffb7e5c001ff50] entry_SYSCALL_64_after_hwframe at ffffffff91c0009b
RIP: 00007f258d9427ae RSP: 00007fffda631d60 RFLAGS: 00000293
...
To fix this, enhance the usage of ORC data. The ORC unwinder often uses
%rbp value, so keep it from exception frames and inactive task stacks.
Signed-off-by: Kazuhito Hagio <k-hagio-ab(a)nec.com>
---
defs.h | 1 +
symbols.c | 1 +
x86_64.c | 115 ++++++++++++++++++++++++++++++++++++++----------------
3 files changed, 83 insertions(+), 34 deletions(-)
diff --git a/defs.h b/defs.h
index ab4f02cc65cf..e76af3c78b69 100644
--- a/defs.h
+++ b/defs.h
@@ -2207,6 +2207,7 @@ struct offset_table { /* stash of commonly-used offsets */
long sock_sk_common;
long sock_common_skc_v6_daddr;
long sock_common_skc_v6_rcv_saddr;
+ long inactive_task_frame_bp;
};
struct size_table { /* stash of commonly-used sizes */
diff --git a/symbols.c b/symbols.c
index b702b9665ec1..a974fc9141a0 100644
--- a/symbols.c
+++ b/symbols.c
@@ -8822,6 +8822,7 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(task_struct_tss_ksp));
fprintf(fp, " task_struct_thread_eip: %ld\n",
OFFSET(task_struct_thread_eip));
+ fprintf(fp, " inactive_task_frame_bp: %ld\n", OFFSET(inactive_task_frame_bp));
fprintf(fp, " inactive_task_frame_ret_addr: %ld\n",
OFFSET(inactive_task_frame_ret_addr));
fprintf(fp, " task_struct_thread_esp: %ld\n",
diff --git a/x86_64.c b/x86_64.c
index 6cac3936b33d..ca14ede52884 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -122,7 +122,7 @@ static int x86_64_do_not_cache_framesize(struct syment *, ulong);
static int x86_64_framesize_cache_func(int, ulong, int *, int, struct syment *);
static ulong x86_64_get_framepointer(struct bt_info *, ulong);
int search_for_eframe_target_caller(struct bt_info *, ulong, int *);
-static int x86_64_get_framesize(struct bt_info *, ulong, ulong);
+static int x86_64_get_framesize(struct bt_info *, ulong, ulong, char *);
static void x86_64_framesize_debug(struct bt_info *);
static void x86_64_get_active_set(void);
static int x86_64_get_kvaddr_ranges(struct vaddr_range *);
@@ -3642,7 +3642,7 @@ in_exception_stack:
bt, ofp);
rsp += SIZE(pt_regs); /* guaranteed kernel mode */
if (bt->eframe_ip && ((framesize = x86_64_get_framesize(bt,
- bt->eframe_ip, rsp)) >= 0))
+ bt->eframe_ip, rsp, NULL)) >= 0))
rsp += framesize;
level++;
irq_eframe = 0;
@@ -3674,7 +3674,7 @@ in_exception_stack:
case BACKTRACE_ENTRY_DISPLAYED:
level++;
if ((framesize = x86_64_get_framesize(bt,
- bt->eframe_ip ? bt->eframe_ip : *up, rsp)) >= 0) {
+ bt->eframe_ip ? bt->eframe_ip : *up, rsp, NULL)) >= 0) {
rsp += framesize;
i += framesize/sizeof(ulong);
}
@@ -3747,7 +3747,7 @@ in_exception_stack:
}
level++;
- if ((framesize = x86_64_get_framesize(bt, bt->instptr, rsp)) >= 0)
+ if ((framesize = x86_64_get_framesize(bt, bt->instptr, rsp, NULL)) >= 0)
rsp += framesize;
}
}
@@ -3799,7 +3799,7 @@ in_exception_stack:
case BACKTRACE_ENTRY_DISPLAYED:
level++;
if ((framesize = x86_64_get_framesize(bt,
- bt->eframe_ip ? bt->eframe_ip : *up, rsp)) >= 0) {
+ bt->eframe_ip ? bt->eframe_ip : *up, rsp, NULL)) >= 0) {
rsp += framesize;
i += framesize/sizeof(ulong);
}
@@ -3909,24 +3909,34 @@ in_exception_stack:
(STREQ(rip_symbol, "thread_return") ||
STREQ(rip_symbol, "schedule") ||
STREQ(rip_symbol, "__schedule"))) {
- if (STREQ(rip_symbol, "__schedule")) {
- i = (rsp - bt->stackbase)/sizeof(ulong);
- x86_64_print_stack_entry(bt, ofp, level,
- i, bt->instptr);
- level++;
- rsp = __schedule_frame_adjust(rsp, bt);
- if (STREQ(closest_symbol(bt->instptr), "schedule"))
+ if ((machdep->flags & ORC) && VALID_MEMBER(inactive_task_frame_ret_addr)) {
+ /*
+ * %rsp should have the address of inactive_task_frame, so
+ * skip the registers before ret_addr to adjust rsp.
+ */
+ if (CRASHDEBUG(1))
+ fprintf(fp, "rsp: %lx rbp: %lx\n", rsp, bt->bptr);
+ rsp += OFFSET(inactive_task_frame_ret_addr);
+ } else {
+ if (STREQ(rip_symbol, "__schedule")) {
+ i = (rsp - bt->stackbase)/sizeof(ulong);
+ x86_64_print_stack_entry(bt, ofp, level,
+ i, bt->instptr);
+ level++;
+ rsp = __schedule_frame_adjust(rsp, bt);
+ if (STREQ(closest_symbol(bt->instptr), "schedule"))
+ bt->flags |= BT_SCHEDULE;
+ } else
bt->flags |= BT_SCHEDULE;
- } else
- bt->flags |= BT_SCHEDULE;
-
- if (bt->flags & BT_SCHEDULE) {
- i = (rsp - bt->stackbase)/sizeof(ulong);
- x86_64_print_stack_entry(bt, ofp, level,
- i, bt->instptr);
- bt->flags &= ~(ulonglong)BT_SCHEDULE;
- rsp += sizeof(ulong);
- level++;
+
+ if (bt->flags & BT_SCHEDULE) {
+ i = (rsp - bt->stackbase)/sizeof(ulong);
+ x86_64_print_stack_entry(bt, ofp, level,
+ i, bt->instptr);
+ bt->flags &= ~(ulonglong)BT_SCHEDULE;
+ rsp += sizeof(ulong);
+ level++;
+ }
}
}
@@ -3957,7 +3967,7 @@ in_exception_stack:
irq_eframe = 0;
bt->flags |= BT_EFRAME_TARGET;
if (bt->eframe_ip && ((framesize = x86_64_get_framesize(bt,
- bt->eframe_ip, rsp)) >= 0))
+ bt->eframe_ip, rsp, NULL)) >= 0))
rsp += framesize;
bt->flags &= ~BT_EFRAME_TARGET;
}
@@ -4044,7 +4054,7 @@ in_exception_stack:
case BACKTRACE_ENTRY_DISPLAYED:
level++;
if ((framesize = x86_64_get_framesize(bt,
- bt->eframe_ip ? bt->eframe_ip : *up, rsp)) >= 0) {
+ bt->eframe_ip ? bt->eframe_ip : *up, rsp, (char *)up)) >= 0) {
rsp += framesize;
i += framesize/sizeof(ulong);
}
@@ -4755,7 +4765,8 @@ x86_64_exception_frame(ulong flags, ulong kvaddr, char *local,
bt->instptr = rip;
bt->stkptr = rsp;
bt->bptr = rbp;
- }
+ } else if (machdep->flags & ORC)
+ bt->bptr = rbp;
if (kvaddr)
FREEBUF(pt_regs_buf);
@@ -5315,6 +5326,10 @@ x86_64_get_sp(struct bt_info *bt)
OFFSET(thread_struct_rsp), KVADDR,
&rsp, sizeof(void *),
"thread_struct rsp", FAULT_ON_ERROR);
+ if ((machdep->flags & ORC) && VALID_MEMBER(inactive_task_frame_bp)) {
+ readmem(rsp + OFFSET(inactive_task_frame_bp), KVADDR, &bt->bptr,
+ sizeof(void *), "inactive_task_frame.bp", FAULT_ON_ERROR);
+ }
return rsp;
}
@@ -6421,6 +6436,9 @@ x86_64_ORC_init(void)
orc->__stop_orc_unwind = symbol_value("__stop_orc_unwind");
orc->orc_lookup = symbol_value("orc_lookup");
+ MEMBER_OFFSET_INIT(inactive_task_frame_bp, "inactive_task_frame", "bp");
+ MEMBER_OFFSET_INIT(inactive_task_frame_ret_addr, "inactive_task_frame", "ret_addr");
+
machdep->flags |= ORC;
}
@@ -8489,7 +8507,7 @@ search_for_eframe_target_caller(struct bt_info *bt, ulong stkptr, int *framesize
(BT_OLD_BACK_TRACE|BT_TEXT_SYMBOLS|BT_TEXT_SYMBOLS_ALL|BT_FRAMESIZE_DISABLE)
static int
-x86_64_get_framesize(struct bt_info *bt, ulong textaddr, ulong rsp)
+x86_64_get_framesize(struct bt_info *bt, ulong textaddr, ulong rsp, char *stack_ptr)
{
int c, framesize, instr, arg, max;
struct syment *sp;
@@ -8590,19 +8608,48 @@ x86_64_get_framesize(struct bt_info *bt, ulong textaddr, ulong rsp)
if ((machdep->flags & ORC) && (korc = orc_find(textaddr))) {
if (CRASHDEBUG(1)) {
fprintf(fp,
- "rsp: %lx textaddr: %lx framesize: %d -> spo: %d bpo: %d spr: %d bpr: %d type: %d %s",
+ "rsp: %lx textaddr: %lx framesize: %d -> spo: %d bpo: %d spr: %d bpr: %d type: %d",
rsp, textaddr, framesize, korc->sp_offset, korc->bp_offset,
- korc->sp_reg, korc->bp_reg, korc->type,
- (korc->type == ORC_TYPE_CALL) && (korc->sp_reg == ORC_REG_SP) ? "" : "(UNUSED)");
+ korc->sp_reg, korc->bp_reg, korc->type);
if (MEMBER_EXISTS("orc_entry", "end"))
fprintf(fp, " end: %d", korc->end);
fprintf(fp, "\n");
}
- if ((korc->type == ORC_TYPE_CALL) && (korc->sp_reg == ORC_REG_SP)) {
- framesize = (korc->sp_offset - 8);
- return (x86_64_framesize_cache_func(FRAMESIZE_ENTER, textaddr,
- &framesize, exception, NULL));
+ if (korc->type == ORC_TYPE_CALL) {
+ ulong prev_sp = 0, prev_bp = 0;
+ framesize = -1;
+
+ if (korc->sp_reg == ORC_REG_SP) {
+ framesize = (korc->sp_offset - 8);
+
+ /* rsp points to a return address, so +8 to use sp_offset */
+ prev_sp = (rsp + 8) + korc->sp_offset;
+ if (CRASHDEBUG(1))
+ fprintf(fp, "rsp: %lx prev_sp: %lx\n", rsp, prev_sp);
+ } else if ((korc->sp_reg == ORC_REG_BP) && bt->bptr) {
+ prev_sp = bt->bptr + korc->sp_offset;
+ framesize = (prev_sp - (rsp + 8) - 8);
+ if (CRASHDEBUG(1))
+ fprintf(fp, "rsp: %lx rbp: %lx prev_sp: %lx framesize: %d\n",
+ rsp, bt->bptr, prev_sp, framesize);
+ }
+
+ if ((korc->bp_reg == ORC_REG_PREV_SP) && prev_sp) {
+ prev_bp = prev_sp + korc->bp_offset;
+ if (stack_ptr && INSTACK(prev_bp, bt)) {
+ bt->bptr = ULONG(stack_ptr + (prev_bp - rsp));
+ if (CRASHDEBUG(1))
+ fprintf(fp, "rsp: %lx prev_sp: %lx prev_bp: %lx -> %lx\n",
+ rsp, prev_sp, prev_bp, bt->bptr);
+ } else
+ bt->bptr = 0;
+ } else if ((korc->bp_reg != ORC_REG_UNDEFINED))
+ bt->bptr = 0;
+
+ if (framesize >= 0)
+ /* Do not cache this, possibly it may be variable. */
+ return framesize;
}
}
@@ -8758,7 +8805,7 @@ x86_64_framesize_debug(struct bt_info *bt)
if (!bt->hp->eip)
error(INFO, "x86_64_framesize_debug: ignoring command\n");
else
- x86_64_get_framesize(bt, bt->hp->eip, 0);
+ x86_64_get_framesize(bt, bt->hp->eip, 0, NULL);
break;
case -3:
--
2.31.1
1 year, 6 months
Questions on multi-thread for crash
by Tao Liu
Hello,
Recently I made an attempt to introduce a thread pool for crash utility, to
optimize the performance of crash.
One obvious point which can benefit from multi-threading is memory.c:vm_init().
There are hundreds of MEMBER_OFFSET_INIT() related symbol resolving functions,
and most of the symbols are independent from each other, by careful arrangement,
they can be invoked parallelly. By doing so, we can shorten the waiting time of
crash starting.
The implementation is abstracted as the following:
Before multi-threading:
MEMBER_OFFSET_INIT(task_struct_mm, "task_struct", "mm");
MEMBER_OFFSET_INIT(mm_struct_mmap, "mm_struct", "mmap");
After multi-threading:
create_threadpool(&pool, 3);
...
MEMBER_OFFSET_INIT_PARA(pool, task_struct_mm, "task_struct", "mm");
MEMBER_OFFSET_INIT_PARA(pool, mm_struct_mmap, "mm_struct", "mmap");
...
wait_and_destroy_threadpool(pool);
MEMBER_OFFSET_INIT_PARA just append the task to the work queue of thread pool
and continues, it's up to the pool to schedule the worker thread to do the
symbol resolving work.
However, after enable multi-threading, I noticed there are always random errors
from gdb. From segfault to broken stack, it seems gdb is not thread safe at
all...
For example one error listed as follows:
Thread 10 "crash" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc4f00640 (LWP 72950)]
c_yylex () at /sources/up-crash/gdb-10.2/gdb/c-exp.y:3250
3250 if (pstate->language ()->la_language != language_cplus
(gdb) bt
#0 c_yylex () at /sources/up-crash/gdb-10.2/gdb/c-exp.y:3250
#1 c_yyparse () at /sources/up-crash/gdb-10.2/gdb/c-exp.c.tmp:2092
#2 0x00000000006f62d7 in c_parse (par_state=<optimized out>) at /sources/
up-crash/gdb-10.2/gdb/c-exp.y:3414
#3 0x0000000000894eac in parse_exp_in_context (stringptr=0x7fffc4efeff8,
pc=<optimized out>, block=<optimized out>, comma=0, out_subexp=0x0,
tracker=0x7fffc4efef10, cstate=0x0, void_context_p=0) at parse.c:1122
#4 0x00000000008951d6 in parse_exp_1 (tracker=0x0, comma=0, block=0x0,
pc=0, stringptr=0x7fffc4efeff8) at parse.c:1031
#5 parse_expression (string=<optimized out>, string@entry=0x7fffc4eff140
"slab_s", tracker=tracker@entry=0x0) at parse.c:1166
#6 0x000000000092039a in gdb_get_datatype (req=0x7fffc4eff720) at symtab.c:7239
#7 gdb_command_funnel_1 (req=0x7fffc4eff720) at symtab.c:7018
#8 0x00000000009206de in gdb_command_funnel (req=0x7fffc4eff720) at symtab.c:6956
#9 0x00000000005ad137 in gdb_interface (req=0x7fffc4eff720) at gdb_interface.c:409
#10 0x00000000005fe76c in datatype_info (name=0xab9700 "slab_s",
member=0xaba8d8 "list", dm=0x0) at symbols.c:5708
#11 0x0000000000517a85 in member_offset_init_slab_s_list_slab_s_list ()
at memory.c:659
#12 0x000000000068168f in group_routine (args=<optimized out>) at thpool.c:81
#13 0x00007ffff7a48b17 in start_thread () from /lib64/libc.so.6
#14 0x00007ffff7acd6c0 in clone3 () from /lib64/libc.so.6
(gdb) p pstate
$1 = (parser_state *) 0x0
$ cat -n /sources/up-crash/gdb-10.2/gdb/c-exp.y
66 /* The state of the parser, used internally when we are parsing the
67 expression. */
68
69 static struct parser_state *pstate = NULL;
pstate is a global variable and not thread safe, the value must be changed by
someone else...
Now the project has reached a dead end. Because making gdb thread safe is an
impossible mission to me. Is there any advice or suggestions? Thanks in advance!
Thanks!
Tao Liu
1 year, 6 months
Re: [Crash-utility] [PATCH] Fix C99 compatibility issues in embedded copy of GDB
by lijiang
Hi, Florian
Thank you for the patch.
On Tue, Feb 14, 2023 at 3:06 PM <crash-utility-request(a)redhat.com> wrote:
> Date: Tue, 14 Feb 2023 08:06:39 +0100
> From: Florian Weimer <fweimer(a)redhat.com>
> To: crash-utility(a)redhat.com
> Subject: [Crash-utility] [PATCH] Fix C99 compatibility issues in
> embedded copy of GDB
> Message-ID: <87sff8buc3.fsf@totally-fudged-out-message-id>
> Content-Type: text/plain
>
> These issues have been fixed in upstream GDB already:
>
Can you help add the related commits here? That will help us to understand
the current issues and patch.
> In the file bfd/elf-bfd.h, startswith is now used in stead of
> strncmp. libiberty was fixed via an import from GCC. Readline
> 8.1 has been imported and has these issues fixed upstream.
>
> Does it have any specific gcc compile options(stricter c99 mode)? Or could
you please
explain more details?
> While at it, also update the bundled copy of <sys/cdefs.h> in
> gnulib. This header file unfortunately shadows the glibc version,
> causing build failures on ppc64le if it is too old.
>
Is this a specific Fedora related issue? Currently, it has a Fedora Only
patch as below:
--- a/gdb-10.2.patch
+++ b/gdb-10.2.patch
@@ -2078,3 +2078,14 @@ exit 0
return new_type;
}
+--- gdb-10.2/gnulib/import/libc-config.h.orig
++++ gdb-10.2/gnulib/import/libc-config.h
+@@ -156,7 +156,7 @@
+ #undef __warndecl
+
+ /* Include our copy of glibc <sys/cdefs.h>. */
+-#include <cdefs.h>
++#include <sys/cdefs.h>
+
+ /* <cdefs.h> __inline is too pessimistic for non-GCC. */
+ #undef __inline
I tried applying the above patch to upstream crash-utility, and it doesn't
happen build failure anymore. But I'm not sure if this is the same issue.
Thanks.
Lianbo
---
> Also submitted as a PR against Fedora rawhide:
>
> <https://src.fedoraproject.org/rpms/crash/pull-request/2>
>
> gdb-10.2.patch | 1019 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 1018 insertions(+), 1 deletion(-)
>
> diff --git a/gdb-10.2.patch b/gdb-10.2.patch
> index aa34743..fc560dd 100644
> --- a/gdb-10.2.patch
> +++ b/gdb-10.2.patch
> @@ -12,7 +12,14 @@ tar xvzmf gdb-10.2.tar.gz \
> gdb-10.2/gdb/symtab.c \
> gdb-10.2/gdb/printcmd.c \
> gdb-10.2/gdb/symfile.c \
> - gdb-10.2/gdb/Makefile.in
> + gdb-10.2/gdb/Makefile.in \
> + gdb-10.2/bfd/elf-bfd.h \
> + gdb-10.2/gnulib/import/cdefs.h \
> + gdb-10.2/libiberty/aclocal.m4 \
> + gdb-10.2/libiberty/configure \
> + gdb-10.2/readline/readline/aclocal.m4 \
> + gdb-10.2/readline/readline/configure \
> + gdb-10.2/readline/readline/configure.ac \
>
> exit 0
>
> @@ -2078,3 +2085,1013 @@ exit 0
>
> return new_type;
> }
> +diff --git gdb-10.2.orig/bfd/elf-bfd.h gdb-10.2/bfd/elf-bfd.h
> +index eebdf9a..775d96c 100644
> +--- gdb-10.2.orig/bfd/elf-bfd.h
> ++++ gdb-10.2/bfd/elf-bfd.h
+@@ -27,6 +27,8 @@
> + #include "elf/internal.h"
> + #include "bfdlink.h"
> +
> ++#include <string.h>
> ++
> + #ifdef __cplusplus
> + extern "C" {
> + #endif
> +diff --git gdb-10.2.orig/gnulib/import/cdefs.h
> gdb-10.2/gnulib/import/cdefs.h
> +index d8e4a00..c37a3ff 100644
> +--- gdb-10.2.orig/gnulib/import/cdefs.h
> ++++ gdb-10.2/gnulib/import/cdefs.h
> +@@ -1,17 +1,18 @@
> +-/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
> ++/* Copyright (C) 1992-2023 Free Software Foundation, Inc.
> ++ Copyright The GNU Toolchain Authors.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> +- modify it under the terms of the GNU General Public
> ++ modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> +- version 3 of the License, or (at your option) any later version.
> ++ version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +- General Public License for more details.
> ++ Lesser General Public License for more details.
> +
> +- You should have received a copy of the GNU General Public
> ++ You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +@@ -25,16 +26,38 @@
> +
> + /* The GNU libc does not support any K&R compilers or the traditional
> mode
> + of ISO C compilers anymore. Check for some of the combinations not
> +- anymore supported. */
> +-#if defined __GNUC__ && !defined __STDC__
> +-# error "You need a ISO C conforming compiler to use the glibc headers"
> ++ supported anymore. */
> ++#if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus
> ++# error "You need a ISO C or C++ conforming compiler to use the glibc
> headers"
> + #endif
> +
> + /* Some user header file might have defined this before. */
> + #undef __P
> + #undef __PMT
> +
> +-#ifdef __GNUC__
> ++/* Compilers that lack __has_attribute may object to
> ++ #if defined __has_attribute && __has_attribute (...)
> ++ even though they do not need to evaluate the right-hand side of the
> &&.
> ++ Similarly for __has_builtin, etc. */
> ++#if (defined __has_attribute \
> ++ && (!defined __clang_minor__ \
> ++ || 3 < __clang_major__ + (5 <= __clang_minor__)))
> ++# define __glibc_has_attribute(attr) __has_attribute (attr)
> ++#else
> ++# define __glibc_has_attribute(attr) 0
> ++#endif
> ++#ifdef __has_builtin
> ++# define __glibc_has_builtin(name) __has_builtin (name)
> ++#else
> ++# define __glibc_has_builtin(name) 0
> ++#endif
> ++#ifdef __has_extension
> ++# define __glibc_has_extension(ext) __has_extension (ext)
> ++#else
> ++# define __glibc_has_extension(ext) 0
> ++#endif
> ++
> ++#if defined __GNUC__ || defined __clang__
> +
> + /* All functions, except those with callbacks or those that
> + synchronize memory, are leaf functions. */
> +@@ -47,21 +70,26 @@
> + # endif
> +
> + /* GCC can always grok prototypes. For C++ programs we add throw()
> +- to help it optimize the function calls. But this works only with
> +- gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
> ++ to help it optimize the function calls. But this only works with
> ++ gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
> + as non-throwing using a function attribute since programs can use
> + the -fexceptions options for C code as well. */
> +-# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
> ++# if !defined __cplusplus \
> ++ && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
> + # define __THROW __attribute__ ((__nothrow__ __LEAF))
> + # define __THROWNL __attribute__ ((__nothrow__))
> + # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
> + # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
> + # else
> +-# if defined __cplusplus && __GNUC_PREREQ (2,8)
> +-# define __THROW throw ()
> +-# define __THROWNL throw ()
> +-# define __NTH(fct) __LEAF_ATTR fct throw ()
> +-# define __NTHNL(fct) fct throw ()
> ++# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
> ++# if __cplusplus >= 201103L
> ++# define __THROW noexcept (true)
> ++# else
> ++# define __THROW throw ()
> ++# endif
> ++# define __THROWNL __THROW
> ++# define __NTH(fct) __LEAF_ATTR fct __THROW
> ++# define __NTHNL(fct) fct __THROW
> + # else
> + # define __THROW
> + # define __THROWNL
> +@@ -70,7 +98,7 @@
> + # endif
> + # endif
> +
> +-#else /* Not GCC. */
> ++#else /* Not GCC or clang. */
> +
> + # if (defined __cplusplus \
> + || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
> +@@ -83,16 +111,7 @@
> + # define __THROWNL
> + # define __NTH(fct) fct
> +
> +-#endif /* GCC. */
> +-
> +-/* Compilers that are not clang may object to
> +- #if defined __clang__ && __has_extension(...)
> +- even though they do not need to evaluate the right-hand side of the
> &&. */
> +-#if defined __clang__ && defined __has_extension
> +-# define __glibc_clang_has_extension(ext) __has_extension (ext)
> +-#else
> +-# define __glibc_clang_has_extension(ext) 0
> +-#endif
> ++#endif /* GCC || clang. */
> +
> + /* These two macros are not used in glibc anymore. They are kept here
> + only because some other projects expect the macros to be defined. */
> +@@ -123,14 +142,70 @@
> + #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
> + #define __bos0(ptr) __builtin_object_size (ptr, 0)
> +
> ++/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when
> available. */
> ++#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0)
> \
> ++ || __GNUC_PREREQ (12, 0))
> ++# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
> ++# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
> ++#else
> ++# define __glibc_objsize0(__o) __bos0 (__o)
> ++# define __glibc_objsize(__o) __bos (__o)
> ++#endif
> ++
> ++#if __USE_FORTIFY_LEVEL > 0
> ++/* Compile time conditions to choose between the regular, _chk and
> _chk_warn
> ++ variants. These conditions should get evaluated to constant and
> optimized
> ++ away. */
> ++
> ++#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
> ++#define __glibc_unsigned_or_positive(__l) \
> ++ ((__typeof (__l)) 0 < (__typeof (__l)) -1
> \
> ++ || (__builtin_constant_p (__l) && (__l) > 0))
> ++
> ++/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
> ++ condition can be folded to a constant and if it is true, or unknown
> (-1) */
> ++#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
> ++ ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1)
> \
> ++ || (__glibc_unsigned_or_positive (__l)
> \
> ++ && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__)
> (__l), \
> ++ (__s), (__osz)))
> \
> ++ && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
> ++
> ++/* Conversely, we know at compile time that the length is unsafe if the
> ++ __L * __S <= __OBJSZ condition can be folded to a constant and if it
> is
> ++ false. */
> ++#define __glibc_unsafe_len(__l, __s, __osz) \
> ++ (__glibc_unsigned_or_positive (__l)
> \
> ++ && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__)
> (__l), \
> ++ __s, __osz))
> \
> ++ && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
> ++
> ++/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
> ++ declared. */
> ++
> ++#define __glibc_fortify(f, __l, __s, __osz, ...) \
> ++ (__glibc_safe_or_unknown_len (__l, __s, __osz)
> \
> ++ ? __ ## f ## _alias (__VA_ARGS__)
> \
> ++ : (__glibc_unsafe_len (__l, __s, __osz)
> \
> ++ ? __ ## f ## _chk_warn (__VA_ARGS__, __osz)
> \
> ++ : __ ## f ## _chk (__VA_ARGS__, __osz)))
> ++
> ++/* Fortify function f, where object size argument passed to f is the
> number of
> ++ elements and not total size. */
> ++
> ++#define __glibc_fortify_n(f, __l, __s, __osz, ...) \
> ++ (__glibc_safe_or_unknown_len (__l, __s, __osz)
> \
> ++ ? __ ## f ## _alias (__VA_ARGS__)
> \
> ++ : (__glibc_unsafe_len (__l, __s, __osz)
> \
> ++ ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s))
> \
> ++ : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))
> ++#endif
> ++
> + #if __GNUC_PREREQ (4,3)
> +-# define __warndecl(name, msg) \
> +- extern void name (void) __attribute__((__warning__ (msg)))
> + # define __warnattr(msg) __attribute__((__warning__ (msg)))
> + # define __errordecl(name, msg) \
> + extern void name (void) __attribute__((__error__ (msg)))
> + #else
> +-# define __warndecl(name, msg) extern void name (void)
> + # define __warnattr(msg)
> + # define __errordecl(name, msg) extern void name (void)
> + #endif
> +@@ -142,8 +217,8 @@
> + #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined
> __HP_cc
> + # define __flexarr []
> + # define __glibc_c99_flexarr_available 1
> +-#elif __GNUC_PREREQ (2,97)
> +-/* GCC 2.97 supports C99 flexible array members as an extension,
> ++#elif __GNUC_PREREQ (2,97) || defined __clang__
> ++/* GCC 2.97 and clang support C99 flexible array members as an extension,
> + even when in C89 mode or compiling C++ (any version). */
> + # define __flexarr []
> + # define __glibc_c99_flexarr_available 1
> +@@ -169,7 +244,7 @@
> + Example:
> + int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
> +
> +-#if defined __GNUC__ && __GNUC__ >= 2
> ++#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
> +
> + # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME
> (#alias))
> + # ifdef __cplusplus
> +@@ -194,17 +269,17 @@
> + */
> + #endif
> +
> +-/* GCC has various useful declarations that can be made with the
> +- `__attribute__' syntax. All of the ways we use this do fine if
> +- they are omitted for compilers that don't understand it. */
> +-#if !defined __GNUC__ || __GNUC__ < 2
> ++/* GCC and clang have various useful declarations that can be made with
> ++ the '__attribute__' syntax. All of the ways we use this do fine if
> ++ they are omitted for compilers that don't understand it. */
> ++#if !(defined __GNUC__ || defined __clang__)
> + # define __attribute__(xyz) /* Ignore */
> + #endif
> +
> + /* At some point during the gcc 2.96 development the `malloc' attribute
> + for functions was introduced. We don't want to use it unconditionally
> + (although this would be possible) since it generates warnings. */
> +-#if __GNUC_PREREQ (2,96)
> ++#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
> + # define __attribute_malloc__ __attribute__ ((__malloc__))
> + #else
> + # define __attribute_malloc__ /* Ignore */
> +@@ -219,26 +294,41 @@
> + # define __attribute_alloc_size__(params) /* Ignore. */
> + #endif
> +
> ++/* Tell the compiler which argument to an allocation function
> ++ indicates the alignment of the allocation. */
> ++#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
> ++# define __attribute_alloc_align__(param) \
> ++ __attribute__ ((__alloc_align__ param))
> ++#else
> ++# define __attribute_alloc_align__(param) /* Ignore. */
> ++#endif
> ++
> + /* At some point during the gcc 2.96 development the `pure' attribute
> + for functions was introduced. We don't want to use it unconditionally
> + (although this would be possible) since it generates warnings. */
> +-#if __GNUC_PREREQ (2,96)
> ++#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
> + # define __attribute_pure__ __attribute__ ((__pure__))
> + #else
> + # define __attribute_pure__ /* Ignore */
> + #endif
> +
> + /* This declaration tells the compiler that the value is constant. */
> +-#if __GNUC_PREREQ (2,5)
> ++#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
> + # define __attribute_const__ __attribute__ ((__const__))
> + #else
> + # define __attribute_const__ /* Ignore */
> + #endif
> +
> ++#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
> ++# define __attribute_maybe_unused__ __attribute__ ((__unused__))
> ++#else
> ++# define __attribute_maybe_unused__ /* Ignore */
> ++#endif
> ++
> + /* At some point during the gcc 3.1 development the `used' attribute
> + for functions was introduced. We don't want to use it unconditionally
> + (although this would be possible) since it generates warnings. */
> +-#if __GNUC_PREREQ (3,1)
> ++#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
> + # define __attribute_used__ __attribute__ ((__used__))
> + # define __attribute_noinline__ __attribute__ ((__noinline__))
> + #else
> +@@ -247,7 +337,7 @@
> + #endif
> +
> + /* Since version 3.2, gcc allows marking deprecated functions. */
> +-#if __GNUC_PREREQ (3,2)
> ++#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
> + # define __attribute_deprecated__ __attribute__ ((__deprecated__))
> + #else
> + # define __attribute_deprecated__ /* Ignore */
> +@@ -256,8 +346,8 @@
> + /* Since version 4.5, gcc also allows one to specify the message printed
> + when a deprecated function is used. clang claims to be gcc 4.2, but
> + may also support this feature. */
> +-#if __GNUC_PREREQ (4,5) || \
> +- __glibc_clang_has_extension (__attribute_deprecated_with_message__)
> ++#if __GNUC_PREREQ (4,5) \
> ++ || __glibc_has_extension (__attribute_deprecated_with_message__)
> + # define __attribute_deprecated_msg__(msg) \
> + __attribute__ ((__deprecated__ (msg)))
> + #else
> +@@ -270,7 +360,7 @@
> + If several `format_arg' attributes are given for the same function, in
> + gcc-3.0 and older, all but the last one are ignored. In newer gccs,
> + all designated arguments are considered. */
> +-#if __GNUC_PREREQ (2,8)
> ++#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
> + # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
> + #else
> + # define __attribute_format_arg__(x) /* Ignore */
> +@@ -280,7 +370,7 @@
> + attribute for functions was introduced. We don't want to use it
> + unconditionally (although this would be possible) since it
> + generates warnings. */
> +-#if __GNUC_PREREQ (2,97)
> ++#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
> + # define __attribute_format_strfmon__(a,b) \
> + __attribute__ ((__format__ (__strfmon__, a, b)))
> + #else
> +@@ -288,19 +378,33 @@
> + #endif
> +
> + /* The nonnull function attribute marks pointer parameters that
> +- must not be NULL. Do not define __nonnull if it is already defined,
> +- for portability when this file is used in Gnulib. */
> ++ must not be NULL. This has the name __nonnull in glibc,
> ++ and __attribute_nonnull__ in files shared with Gnulib to avoid
> ++ collision with a different __nonnull in DragonFlyBSD 5.9. */
> ++#ifndef __attribute_nonnull__
> ++# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
> ++# define __attribute_nonnull__(params) __attribute__ ((__nonnull__
> params))
> ++# else
> ++# define __attribute_nonnull__(params)
> ++# endif
> ++#endif
> + #ifndef __nonnull
> +-# if __GNUC_PREREQ (3,3)
> +-# define __nonnull(params) __attribute__ ((__nonnull__ params))
> ++# define __nonnull(params) __attribute_nonnull__ (params)
> ++#endif
> ++
> ++/* The returns_nonnull function attribute marks the return type of the
> function
> ++ as always being non-null. */
> ++#ifndef __returns_nonnull
> ++# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
> ++# define __returns_nonnull __attribute__ ((__returns_nonnull__))
> + # else
> +-# define __nonnull(params)
> ++# define __returns_nonnull
> + # endif
> + #endif
> +
> + /* If fortification mode, we warn about unused results of certain
> + function calls which can lead to problems. */
> +-#if __GNUC_PREREQ (3,4)
> ++#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
> + # define __attribute_warn_unused_result__ \
> + __attribute__ ((__warn_unused_result__))
> + # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
> +@@ -314,7 +418,7 @@
> + #endif
> +
> + /* Forces a function to be always inlined. */
> +-#if __GNUC_PREREQ (3,2)
> ++#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
> + /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
> + it conflicts with this definition. Therefore undefine it first to
> + allow either header to be included first. */
> +@@ -327,7 +431,7 @@
> +
> + /* Associate error messages with the source location of the call site
> rather
> + than with the source location inside the function. */
> +-#if __GNUC_PREREQ (4,3)
> ++#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
> + # define __attribute_artificial__ __attribute__ ((__artificial__))
> + #else
> + # define __attribute_artificial__ /* Ignore */
> +@@ -370,12 +474,14 @@
> + run in pedantic mode if the uses are carefully marked using the
> + `__extension__' keyword. But this is not generally available before
> + version 2.8. */
> +-#if !__GNUC_PREREQ (2,8)
> ++#if !(__GNUC_PREREQ (2,8) || defined __clang__)
> + # define __extension__ /* Ignore */
> + #endif
> +
> +-/* __restrict is known in EGCS 1.2 and above. */
> +-#if !__GNUC_PREREQ (2,92)
> ++/* __restrict is known in EGCS 1.2 and above, and in clang.
> ++ It works also in C++ mode (outside of arrays), but only when spelled
> ++ as '__restrict', not 'restrict'. */
> ++#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
> + # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
> + # define __restrict restrict
> + # else
> +@@ -385,8 +491,9 @@
> +
> + /* ISO C99 also allows to declare arrays as non-overlapping. The syntax
> is
> + array_name[restrict]
> +- GCC 3.1 supports this. */
> +-#if __GNUC_PREREQ (3,1) && !defined __GNUG__
> ++ GCC 3.1 and clang support this.
> ++ This syntax is not usable in C++ mode. */
> ++#if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
> + # define __restrict_arr __restrict
> + #else
> + # ifdef __GNUC__
> +@@ -401,7 +508,7 @@
> + # endif
> + #endif
> +
> +-#if __GNUC__ >= 3
> ++#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
> + # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
> + # define __glibc_likely(cond) __builtin_expect ((cond), 1)
> + #else
> +@@ -409,15 +516,10 @@
> + # define __glibc_likely(cond) (cond)
> + #endif
> +
> +-#ifdef __has_attribute
> +-# define __glibc_has_attribute(attr) __has_attribute (attr)
> +-#else
> +-# define __glibc_has_attribute(attr) 0
> +-#endif
> +-
> + #if (!defined _Noreturn \
> + && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
> +- && !__GNUC_PREREQ (4,7))
> ++ && !(__GNUC_PREREQ (4,7) \
> ++ || (3 < __clang_major__ + (5 <= __clang_minor__))))
> + # if __GNUC_PREREQ (2,8)
> + # define _Noreturn __attribute__ ((__noreturn__))
> + # else
> +@@ -434,22 +536,63 @@
> + # define __attribute_nonstring__
> + #endif
> +
> ++/* Undefine (also defined in libc-symbols.h). */
> ++#undef __attribute_copy__
> ++#if __GNUC_PREREQ (9, 0)
> ++/* Copies attributes from the declaration or type referenced by
> ++ the argument. */
> ++# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
> ++#else
> ++# define __attribute_copy__(arg)
> ++#endif
> ++
> + #if (!defined _Static_assert && !defined __cplusplus \
> + && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
> +- && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
> ++ && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
> ++ || defined __STRICT_ANSI__))
> + # define _Static_assert(expr, diagnostic) \
> + extern int (*__Static_assert_function (void)) \
> + [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
> + #endif
> +
> +-/* The #ifndef lets Gnulib avoid including these on non-glibc
> +- platforms, where the includes typically do not exist. */
> +-#ifndef __WORDSIZE
> ++/* Gnulib avoids including these, as they don't work on non-glibc or
> ++ older glibc platforms. */
> ++#ifndef __GNULIB_CDEFS
> + # include <bits/wordsize.h>
> + # include <bits/long-double.h>
> + #endif
> +
> +-#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
> ++#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
> ++# ifdef __REDIRECT
> ++
> ++/* Alias name defined automatically. */
> ++# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
> ++# define __LDBL_REDIR_DECL(name) \
> ++ extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
> ++
> ++/* Alias name defined automatically, with leading underscores. */
> ++# define __LDBL_REDIR2_DECL(name) \
> ++ extern __typeof (__##name) __##name \
> ++ __asm (__ASMNAME ("__" #name "ieee128"));
> ++
> ++/* Alias name defined manually. */
> ++# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
> ++# define __LDBL_REDIR1_DECL(name, alias) \
> ++ extern __typeof (name) name __asm (__ASMNAME (#alias));
> ++
> ++# define __LDBL_REDIR1_NTH(name, proto, alias) \
> ++ __REDIRECT_NTH (name, proto, alias)
> ++# define __REDIRECT_NTH_LDBL(name, proto, alias) \
> ++ __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
> ++
> ++/* Unused. */
> ++# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
> ++# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
> ++
> ++# else
> ++_Static_assert (0, "IEEE 128-bits long double requires redirection on
> this platform");
> ++# endif
> ++#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined
> __NO_LONG_DOUBLE_MATH
> + # define __LDBL_COMPAT 1
> + # ifdef __REDIRECT
> + # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto,
> alias)
> +@@ -458,6 +601,8 @@
> + # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name,
> proto, alias)
> + # define __LDBL_REDIR_NTH(name, proto) \
> + __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
> ++# define __LDBL_REDIR2_DECL(name) \
> ++ extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___"
> #name));
> + # define __LDBL_REDIR1_DECL(name, alias) \
> + extern __typeof (name) name __asm (__ASMNAME (#alias));
> + # define __LDBL_REDIR_DECL(name) \
> +@@ -468,11 +613,13 @@
> + __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
> + # endif
> + #endif
> +-#if !defined __LDBL_COMPAT || !defined __REDIRECT
> ++#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0)
> \
> ++ || !defined __REDIRECT
> + # define __LDBL_REDIR1(name, proto, alias) name proto
> + # define __LDBL_REDIR(name, proto) name proto
> + # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
> + # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
> ++# define __LDBL_REDIR2_DECL(name)
> + # define __LDBL_REDIR_DECL(name)
> + # ifdef __REDIRECT
> + # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto,
> alias)
> +@@ -503,7 +650,7 @@
> + check is required to enable the use of generic selection. */
> + #if !defined __cplusplus \
> + && (__GNUC_PREREQ (4, 9) \
> +- || __glibc_clang_has_extension (c_generic_selections) \
> ++ || __glibc_has_extension (c_generic_selections) \
> + || (!defined __GNUC__ && defined __STDC_VERSION__ \
> + && __STDC_VERSION__ >= 201112L))
> + # define __HAVE_GENERIC_SELECTION 1
> +@@ -511,4 +658,50 @@
> + # define __HAVE_GENERIC_SELECTION 0
> + #endif
> +
> ++#if __GNUC_PREREQ (10, 0)
> ++/* Designates a 1-based positional argument ref-index of pointer type
> ++ that can be used to access size-index elements of the pointed-to
> ++ array according to access mode, or at least one element when
> ++ size-index is not provided:
> ++ access (access-mode, <ref-index> [, <size-index>]) */
> ++# define __attr_access(x) __attribute__ ((__access__ x))
> ++/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which
> may
> ++ use the access attribute to get object sizes from function definition
> ++ arguments, so we can't use them on functions we fortify. Drop the
> object
> ++ size hints for such functions. */
> ++# if __USE_FORTIFY_LEVEL == 3
> ++# define __fortified_attr_access(a, o, s) __attribute__ ((__access__
> (a, o)))
> ++# else
> ++# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
> ++# endif
> ++# if __GNUC_PREREQ (11, 0)
> ++# define __attr_access_none(argno) __attribute__ ((__access__
> (__none__, argno)))
> ++# else
> ++# define __attr_access_none(argno)
> ++# endif
> ++#else
> ++# define __fortified_attr_access(a, o, s)
> ++# define __attr_access(x)
> ++# define __attr_access_none(argno)
> ++#endif
> ++
> ++#if __GNUC_PREREQ (11, 0)
> ++/* Designates dealloc as a function to call to deallocate objects
> ++ allocated by the declared function. */
> ++# define __attr_dealloc(dealloc, argno) \
> ++ __attribute__ ((__malloc__ (dealloc, argno)))
> ++# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
> ++#else
> ++# define __attr_dealloc(dealloc, argno)
> ++# define __attr_dealloc_free
> ++#endif
> ++
> ++/* Specify that a function such as setjmp or vfork may return
> ++ twice. */
> ++#if __GNUC_PREREQ (4, 1)
> ++# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
> ++#else
> ++# define __attribute_returns_twice__ /* Ignore. */
> ++#endif
> ++
> + #endif /* sys/cdefs.h */
> +diff --git gdb-10.2.orig/libiberty/aclocal.m4
> gdb-10.2/libiberty/aclocal.m4
> +index 34c0a5b..0e91b90 100644
> +--- gdb-10.2.orig/libiberty/aclocal.m4
> ++++ gdb-10.2/libiberty/aclocal.m4
> +@@ -16,6 +16,8 @@ AC_CACHE_CHECK([for working strncmp],
> ac_cv_func_strncmp_works,
> + [AC_TRY_RUN([
> + /* Test by Jim Wilson and Kaveh Ghazi.
> + Check whether strncmp reads past the end of its string parameters. */
> ++#include <stdlib.h>
> ++#include <string.h>
> + #include <sys/types.h>
> +
> + #ifdef HAVE_FCNTL_H
> +@@ -43,7 +45,8 @@ AC_CACHE_CHECK([for working strncmp],
> ac_cv_func_strncmp_works,
> +
> + #define MAP_LEN 0x10000
> +
> +-main ()
> ++int
> ++main (void)
> + {
> + #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
> + char *p;
> +@@ -149,7 +152,10 @@ if test $ac_cv_os_cray = yes; then
> + fi
> +
> + AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
> +-[AC_TRY_RUN([find_stack_direction ()
> ++[AC_TRY_RUN([#include <stdlib.h>
> ++
> ++int
> ++find_stack_direction (void)
> + {
> + static char *addr = 0;
> + auto char dummy;
> +@@ -161,7 +167,9 @@ AC_CACHE_CHECK(stack direction for C alloca,
> ac_cv_c_stack_direction,
> + else
> + return (&dummy > addr) ? 1 : -1;
> + }
> +-main ()
> ++
> ++int
> ++main (void)
> + {
> + exit (find_stack_direction() < 0);
> + }],
> +diff --git gdb-10.2.orig/libiberty/configure gdb-10.2/libiberty/configure
> +index ff93c9e..2b880a8 100755
> +--- gdb-10.2.orig/libiberty/configure
> ++++ gdb-10.2/libiberty/configure
> +@@ -6724,7 +6724,10 @@ else
> + else
> + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> + /* end confdefs.h. */
> +-find_stack_direction ()
> ++#include <stdlib.h>
> ++
> ++int
> ++find_stack_direction (void)
> + {
> + static char *addr = 0;
> + auto char dummy;
> +@@ -6736,7 +6739,9 @@ find_stack_direction ()
> + else
> + return (&dummy > addr) ? 1 : -1;
> + }
> +-main ()
> ++
> ++int
> ++main (void)
> + {
> + exit (find_stack_direction() < 0);
> + }
> +@@ -7557,6 +7562,8 @@ else
> +
> + /* Test by Jim Wilson and Kaveh Ghazi.
> + Check whether strncmp reads past the end of its string parameters. */
> ++#include <stdlib.h>
> ++#include <string.h>
> + #include <sys/types.h>
> +
> + #ifdef HAVE_FCNTL_H
> +@@ -7584,7 +7591,8 @@ else
> +
> + #define MAP_LEN 0x10000
> +
> +-main ()
> ++int
> ++main (void)
> + {
> + #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
> + char *p;
> +diff --git gdb-10.2.orig/readline/readline/aclocal.m4
> gdb-10.2/readline/readline/aclocal.m4
> +index 1413267..7e7a303 100644
> +--- gdb-10.2.orig/readline/readline/aclocal.m4
> ++++ gdb-10.2/readline/readline/aclocal.m4
> +@@ -10,6 +10,7 @@ AC_DEFUN(BASH_C_LONG_LONG,
> + ac_cv_c_long_long=yes
> + else
> + AC_TRY_RUN([
> ++#include <stdlib.h>
> + int
> + main()
> + {
> +@@ -33,6 +34,7 @@ AC_DEFUN(BASH_C_LONG_DOUBLE,
> + ac_cv_c_long_double=yes
> + else
> + AC_TRY_RUN([
> ++#include <stdlib.h>
> + int
> + main()
> + {
> +@@ -134,6 +136,7 @@ typedef int (*_bashfunc)(const char *, ...);
> + #else
> + typedef int (*_bashfunc)();
> + #endif
> ++#include <stdlib.h>
> + main()
> + {
> + _bashfunc pf;
> +@@ -191,6 +194,7 @@ AC_CACHE_VAL(bash_cv_under_sys_siglist,
> + #ifdef HAVE_UNISTD_H
> + #include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> + #ifndef UNDER_SYS_SIGLIST_DECLARED
> + extern char *_sys_siglist[];
> + #endif
> +@@ -218,6 +222,7 @@ AC_CACHE_VAL(bash_cv_sys_siglist,
> + #ifdef HAVE_UNISTD_H
> + #include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> + #if !HAVE_DECL_SYS_SIGLIST
> + extern char *sys_siglist[];
> + #endif
> +@@ -273,6 +278,7 @@ AC_CACHE_VAL(bash_cv_dup2_broken,
> + [AC_TRY_RUN([
> + #include <sys/types.h>
> + #include <fcntl.h>
> ++#include <stdlib.h>
> + main()
> + {
> + int fd1, fd2, fl;
> +@@ -335,6 +341,7 @@ AC_CACHE_VAL(bash_cv_opendir_not_robust,
> + # include <ndir.h>
> + # endif
> + #endif /* HAVE_DIRENT_H */
> ++#include <stdlib.h>
> + main()
> + {
> + DIR *dir;
> +@@ -514,6 +521,7 @@ AC_TRY_RUN([
> + #include <sys/types.h>
> + #include <sys/time.h>
> + #include <sys/resource.h>
> ++#include <stdlib.h>
> + main()
> + {
> + #ifdef HAVE_QUAD_T
> +@@ -583,6 +591,7 @@ AC_CACHE_VAL(bash_cv_getenv_redef,
> + #ifdef HAVE_UNISTD_H
> + # include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> + #ifndef __STDC__
> + # ifndef const
> + # define const
> +@@ -786,6 +795,7 @@ AC_CACHE_VAL(bash_cv_func_sigsetjmp,
> + #include <sys/types.h>
> + #include <signal.h>
> + #include <setjmp.h>
> ++#include <stdlib.h>
> +
> + main()
> + {
> +@@ -835,8 +845,9 @@ AC_CACHE_VAL(bash_cv_func_strcoll_broken,
> + #if defined (HAVE_LOCALE_H)
> + #include <locale.h>
> + #endif
> ++#include <stringh>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char *v[];
> + {
> +@@ -863,7 +874,7 @@ char *v[];
> + /* Exit with 1 (failure) if these two values are both > 0, since
> + this tests whether strcoll(3) is broken with respect to
> strcmp(3)
> + in the default locale. */
> +- exit (r1 > 0 && r2 > 0);
> ++ return r1 > 0 && r2 > 0;
> + }
> + ], bash_cv_func_strcoll_broken=yes, bash_cv_func_strcoll_broken=no,
> + [AC_MSG_WARN(cannot check strcoll if cross compiling -- defaulting to
> no)
> +@@ -881,6 +892,7 @@ AC_CACHE_VAL(bash_cv_printf_a_format,
> + [AC_TRY_RUN([
> + #include <stdio.h>
> + #include <string.h>
> ++#include <stdlib.h>
> +
> + int
> + main()
> +@@ -1241,6 +1253,7 @@ AC_CACHE_VAL(bash_cv_pgrp_pipe,
> + #ifdef HAVE_UNISTD_H
> + # include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> + main()
> + {
> + # ifdef GETPGRP_VOID
> +@@ -1305,6 +1318,7 @@ AC_CACHE_VAL(bash_cv_must_reinstall_sighandlers,
> + #ifdef HAVE_UNISTD_H
> + #include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> +
> + typedef RETSIGTYPE sigfunc();
> +
> +@@ -1418,6 +1432,7 @@ AC_CACHE_VAL(bash_cv_sys_named_pipes,
> + #ifdef HAVE_UNISTD_H
> + #include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> +
> + /* Add more tests in here as appropriate. */
> + main()
> +@@ -1651,6 +1666,7 @@ AC_CACHE_VAL(bash_cv_unusable_rtsigs,
> + [AC_TRY_RUN([
> + #include <sys/types.h>
> + #include <signal.h>
> ++#include <stdlib.h>
> +
> + #ifndef NSIG
> + # define NSIG 64
> +@@ -1770,7 +1786,7 @@ bash_cv_wcwidth_broken,
> + #include <locale.h>
> + #include <wchar.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char **v;
> + {
> +@@ -1834,6 +1850,7 @@ AC_CACHE_VAL(ac_cv_rl_version,
> + [AC_TRY_RUN([
> + #include <stdio.h>
> + #include <readline/readline.h>
> ++#include <stdlib.h>
> +
> + extern int rl_gnu_readline_p;
> +
> +@@ -1927,7 +1944,7 @@ AC_CACHE_VAL(bash_cv_func_ctype_nonascii,
> + #include <stdio.h>
> + #include <ctype.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char *v[];
> + {
> +@@ -1948,7 +1965,7 @@ char *v[];
> + r1 = isprint(x);
> + x -= 128;
> + r2 = isprint(x);
> +- exit (r1 == 0 || r2 == 0);
> ++ return r1 == 0 || r2 == 0;
> + }
> + ], bash_cv_func_ctype_nonascii=yes, bash_cv_func_ctype_nonascii=no,
> + [AC_MSG_WARN(cannot check ctype macros if cross compiling --
> defaulting to no)
> +@@ -4068,6 +4085,7 @@ AC_DEFUN([BASH_FUNC_SNPRINTF],
> + AC_CACHE_CHECK([for standard-conformant snprintf],
> [bash_cv_func_snprintf],
> + [AC_TRY_RUN([
> + #include <stdio.h>
> ++#include <stdlib.h>
> +
> + main()
> + {
> +@@ -4154,7 +4172,7 @@ AC_CACHE_VAL(bash_cv_wexitstatus_offset,
> +
> + #include <sys/wait.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char **v;
> + {
> +diff --git gdb-10.2.orig/readline/readline/configure
> gdb-10.2/readline/readline/configure
> +index de7499e..a53a885 100755
> +--- gdb-10.2.orig/readline/readline/configure
> ++++ gdb-10.2/readline/readline/configure
> +@@ -1,5 +1,5 @@
> + #! /bin/sh
> +-# From configure.ac for Readline 8.0, version 2.85.
> ++# From configure.ac for Readline 8.0, version 2.86.
> + # Guess values for system-dependent variables and create Makefiles.
> + # Generated by GNU Autoconf 2.69 for readline 8.0.
> + #
> +@@ -5316,6 +5316,7 @@ else
> + #ifdef HAVE_UNISTD_H
> + #include <unistd.h>
> + #endif
> ++#include <stdlib.h>
> +
> + typedef RETSIGTYPE sigfunc();
> +
> +@@ -5346,7 +5347,7 @@ int s;
> + nsigint++;
> + }
> +
> +-main()
> ++int main(void)
> + {
> + nsigint = 0;
> + set_signal_handler(SIGINT, sigint);
> +@@ -5396,8 +5397,9 @@ else
> + #include <sys/types.h>
> + #include <signal.h>
> + #include <setjmp.h>
> ++#include <stdlib.h>
> +
> +-main()
> ++int main(void)
> + {
> + #if !defined (_POSIX_VERSION) || !defined (HAVE_POSIX_SIGNALS)
> + exit (1);
> +@@ -5499,8 +5501,9 @@ else
> + #if defined (HAVE_LOCALE_H)
> + #include <locale.h>
> + #endif
> ++#include <string.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char *v[];
> + {
> +@@ -5527,7 +5530,7 @@ char *v[];
> + /* Exit with 1 (failure) if these two values are both > 0, since
> + this tests whether strcoll(3) is broken with respect to
> strcmp(3)
> + in the default locale. */
> +- exit (r1 > 0 && r2 > 0);
> ++ return r1 > 0 && r2 > 0;
> + }
> +
> + _ACEOF
> +@@ -5570,7 +5573,7 @@ else
> + #include <stdio.h>
> + #include <ctype.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char *v[];
> + {
> +@@ -5591,7 +5594,7 @@ char *v[];
> + r1 = isprint(x);
> + x -= 128;
> + r2 = isprint(x);
> +- exit (r1 == 0 || r2 == 0);
> ++ return r1 == 0 || r2 == 0;
> + }
> +
> + _ACEOF
> +@@ -6713,7 +6716,7 @@ else
> + #include <locale.h>
> + #include <wchar.h>
> +
> +-main(c, v)
> ++int main(c, v)
> + int c;
> + char **v;
> + {
> +diff --git gdb-10.2.orig/readline/readline/configure.ac
> gdb-10.2/readline/readline/configure.ac
> +index b9b3e1c..399920c 100644
> +--- gdb-10.2.orig/readline/readline/configure.ac
> ++++ gdb-10.2/readline/readline/configure.ac
> +@@ -5,7 +5,7 @@ dnl report bugs to chet(a)po.cwru.edu
> + dnl
> + dnl Process this file with autoconf to produce a configure script.
> +
> +-# Copyright (C) 1987-2018 Free Software Foundation, Inc.
> ++# Copyright (C) 1987-2019 Free Software Foundation, Inc.
> +
> + # This program is free software: you can redistribute it and/or modify
> + # it under the terms of the GNU General Public License as published by
> +@@ -20,7 +20,7 @@ dnl Process this file with autoconf to produce a
> configure script.
> + # You should have received a copy of the GNU General Public License
> + # along with this program. If not, see <http://www.gnu.org/licenses/
> >.
> +
> +-AC_REVISION([for Readline 8.0, version 2.85])
> ++AC_REVISION([for Readline 8.0, version 2.86])
> +
> + m4_include([../../config/override.m4])
> +
> --
> 2.39.1
>
1 year, 6 months
[PATCH] Fix for "bt" command incorrectly printing eframe stack with a bogus warning
by Lianbo Jiang
Kernel commit 7d65f4a65532 ("irq: Consolidate do_softirq() arch overriden
implementations") renamed the call_softirq to do_softirq_own_stack.
Crash may incorrectly output the eframe stack with a warning as below:
crash> foreach bt
...
PID: 0 TASK: ffff914f820a8000 CPU: 25 COMMAND: "swapper/25"
#0 [fffffe0000504e48] crash_nmi_callback at ffffffffa665d763
#1 [fffffe0000504e50] nmi_handle at ffffffffa662a423
#2 [fffffe0000504ea8] default_do_nmi at ffffffffa6fe7dc9
#3 [fffffe0000504ec8] do_nmi at ffffffffa662a97f
#4 [fffffe0000504ef0] end_repeat_nmi at ffffffffa70015e8
[exception RIP: clone_endio+172]
RIP: ffffffffc005c1ec RSP: ffffa1d403d08e98 RFLAGS: 00000246
RAX: 0000000000000000 RBX: ffff915326fba230 RCX: 0000000000000018
RDX: ffffffffc0075400 RSI: 0000000000000000 RDI: ffff915326fba230
RBP: ffff915326fba1c0 R8: 0000000000001000 R9: ffff915308d6d2a0
R10: 000000a97dfe5e10 R11: ffffa1d40038fe98 R12: ffff915302babc40
R13: ffff914f94360000 R14: 0000000000000000 R15: 0000000000000000
ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
--- <NMI exception stack> ---
#5 [ffffa1d403d08e98] clone_endio at ffffffffc005c1ec [dm_mod]
#6 [ffffa1d403d08ed0] blk_update_request at ffffffffa6a96954
#7 [ffffa1d403d08f10] scsi_end_request at ffffffffa6c9b968
#8 [ffffa1d403d08f48] scsi_io_completion at ffffffffa6c9bb3e
#9 [ffffa1d403d08f90] blk_complete_reqs at ffffffffa6aa0e95
#10 [ffffa1d403d08fa0] __softirqentry_text_start at ffffffffa72000dc
#11 [ffffa1d403d08ff0] do_softirq_own_stack at ffffffffa7000f9a
--- <IRQ stack> ---
#12 [ffffa1d40038fe70] do_softirq_own_stack at ffffffffa7000f9a
[exception RIP: unknown or invalid address]
RIP: 0000000000000000 RSP: 0000000000000000 RFLAGS: 00000000
RAX: ffffffffa672eae5 RBX: ffffffffa83b34e0 RCX: ffffffffa672eb12
RDX: 0000000000000010 RSI: 8b7d6c8869010c00 RDI: 0000000000000085
RBP: 0000000000000286 R8: ffff914f820a8000 R9: ffffffffa67a94e0
R10: 0000000000000286 R11: ffffffffa66fb4c5 R12: ffffffffa67a898b
R13: 0000000000000000 R14: fffffffffffffff8 R15: ffffffffa67a1e68
ORIG_RAX: 0000000000000000 CS: 0000 SS: ffffffffa672edff
bt: WARNING: possibly bogus exception frame
#13 [ffffa1d40038ff30] start_secondary at ffffffffa665fa2c
#14 [ffffa1d40038ff50] secondary_startup_64_no_verify at ffffffffa6600116
...
Also no exception frame when coming from do_softirq_own_stack.
Reported-by: Marco Patalano <mpatalan(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
x86_64.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/x86_64.c b/x86_64.c
index 5b671bd97775..3428bed417df 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -3825,10 +3825,11 @@ in_exception_stack:
up -= 1;
bt->instptr = *up;
/*
- * No exception frame when coming from call_softirq.
+ * No exception frame when coming from call_softirq
+ * or do_softirq_own_stack.
*/
if ((sp = value_search(bt->instptr, &offset)) &&
- STREQ(sp->name, "call_softirq"))
+ (STREQ(sp->name, "call_softirq") || STREQ(sp->name, "do_softirq_own_stack")))
irq_eframe = 0;
bt->frameptr = 0;
done = FALSE;
--
2.37.1
1 year, 6 months
Re: [Crash-utility] [PATCH] Fix for "bt" command incorrectly printing eframe stack with a bogus warning
by lijiang
On Thu, Feb 16, 2023 at 8:48 AM <crash-utility-request(a)redhat.com> wrote:
> Hello,
>
> For upstream crash, and this is more a general thought, what about
> ordering tests with most recent kernel changes being tested first:
>
>
Good question.
For example, in Lianbo's case, instead of:
> - (STREQ(sp->name, "call_softirq") || STREQ(sp->name,
> "do_softirq_own_stack")))
> What about reversing the order of the tests:
> + (STREQ(sp->name, " do_softirq_own_stack") ||
> STREQ(sp->name, " call_softirq")))
>
> As distros tend to move fast forward, ordering tests with most recent
> kernel changes being tested first would make sense.
>
>
It's true. If this happens during the bootup and there are hundreds of
symbols, it will benefit more. Otherwise the cumulative effect is small, the
impact is almost negligible.
But anyway, this still makes sense. Thank you for the discussion, Georges.
Lianbo
1 year, 6 months
[PATCH] Enhance the "kmem -i" option to properly display the statistics of CACHED
by Lianbo Jiang
The "kmem -i" option may output the bogus statistics of CACHED, which
might be observed when some extreme situations occur in kernel, such as
OOM, disk IO errors, etc.
The following result of calculation may be a negative value, refer to
the dump_kmeminfo():
page_cache_size = nr_file_pages - swapper_space_nrpages - buffer_pages;
As a result, the negative value will be converted to unsigned long
integer, eventually it overflows and gets a big integer.
crash> kmem -i
PAGES TOTAL PERCENTAGE
TOTAL MEM 255314511 973.9 GB ----
FREE 533574 2 GB 0% of TOTAL MEM
USED 254780937 971.9 GB 99% of TOTAL MEM
SHARED 1713 6.7 MB 0% of TOTAL MEM
BUFFERS 374 1.5 MB 0% of TOTAL MEM
CACHED -114 70368744177664 GB 72251060080% of TOTAL MEM
^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^
...
Let's normalize it to zero to fix such corner cases.
Reported-by: Buland Kumar Singh <bsingh(a)redhat.com>
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
memory.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/memory.c b/memory.c
index e0742c1bd3a4..860a3a978a4d 100644
--- a/memory.c
+++ b/memory.c
@@ -8615,6 +8615,8 @@ dump_kmeminfo(void)
page_cache_size = 0;
+ if (page_cache_size < 0)
+ page_cache_size = 0;
pct = (page_cache_size * 100)/totalram_pages;
fprintf(fp, "%13s %7ld %11s %3ld%% of TOTAL MEM\n",
"CACHED", page_cache_size,
--
2.37.1
1 year, 6 months