我无法使用 gdb 访问/打印结构中整数字段的值。它说无法访问地址。我确定这不是空指针问题。那么这可能是什么原因呢? 任何内存损坏问题?如果是,那么现在如何处理?如何知道根本原因?
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 445266
[New LWP 445267]
[New LWP 445268]
[New LWP 445269]
[New LWP 445270]
[New LWP 445271]
[New LWP 445290]
[New LWP 445291]
[New LWP 445292]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
warning: Target and debugger are in different PID namespaces; thread lists and other data are likely unreliable. Connect to gdbserver inside the container.
__pthread_clockjoin_ex (threadid=139864192313088, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145
145 pthread_join_common.c: No such file or directory.
(gdb) n
Thread 7 "e2" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f34ab7fe700 (LWP 445290)]
0x00007f34b4c38792 in SIsendt (gptr=0x55b38b2f1060, fd=15, ubuf=0x7f347a2f4830 " \r", ulen=3360) at /home/ubuntu/office/nearrt-ric-plt/rmr/src/rmr/si/src/si95/sisendt.c:74
74 if( (fd = tpptr->fd) < 0 || (fd = tpptr->fd) >= FD_SETSIZE ) { // fd user given might not be real, and this might be closed already
(gdb) info locals
status = -1
writefds = <error reading variable writefds (Cannot access memory at address 0x7f34ab2bc8c0)>
execpfds = <error reading variable execpfds (Cannot access memory at address 0x7f34ab2bc940)>
tpptr = 0x2
qptr = <optimized out>
time = {tv_sec = 31, tv_usec = 139864186800368}
sidx = 0
(gdb) bt
#0 0x00007f34b4c38792 in SIsendt (gptr=0x55b38b2f1060, fd=15, ubuf=0x7f347a2f4830 <error: Cannot access memory at address 0x7f347a2f4830>, ulen=3360) at /home/ubuntu/office/nearrt-ric-plt/rmr/src/rmr/si/src/si95/sisendt.c:74
#1 0x00007f34b4c320bb in send_msg (ctx=0x55b38b2cfd80, msg=0x7f3490102830, nn_sock=15, retries=1) at /home/ubuntu/office/nearrt-ric-plt/rmr/src/rmr/si/src/sr_si_static.c:619
Backtrace stopped: Cannot access memory at address 0x7f34ab2bca38
(gdb) p tpptr
$1 = (struct tp_blk *) 0x2
(gdb) p gptr
$2 = (struct ginfo_blk *) 0x55b38b2f1060
(gdb) p ubuf
$3 = 0x7f347a2f4830 <error: Cannot access memory at address 0x7f347a2f4830>
(gdb) p tpptr
$4 = (struct tp_blk *) 0x2
(gdb) p *tpptr -----------> tpptr is not null, still can not access memory why?
Cannot access memory at address 0x2
(gdb) p tpptr->fd
Cannot access memory at address 0x12
(gdb) p tpptr ----------> as said already, tpptr is not null
$5 = (struct tp_blk *) 0x2
(gdb)
(gdb) ptype tpptr->fd -----> this is int
type = int
(gdb) p tpptr->fd ---------> why i am not able to access interger
Cannot access memory at address 0x12
(gdb) ptype tpptr
type = struct tp_blk {
struct tp_blk *next;
struct tp_blk *prev;
int fd;
int flags;
int type;
int family;
struct sockaddr *addr;
struct sockaddr *paddr;
int palen;
struct ioq_blk *squeue;
struct ioq_blk *sqtail;
long long qcount;
long long sent;
long long rcvd;
} *
(gdb)
以下是供上述参考的代码片段。请参阅第 74 行
49 extern int SIsendt( struct ginfo_blk *gptr, int fd, char *ubuf, int ulen ) {
50 int status = SI_ERROR; // assume we fail
51 fd_set writefds; // local write fdset to check blockage
52 fd_set execpfds; // exception fdset to check errors
53 struct tp_blk *tpptr; // pointer at the tp_blk for the session
54 struct ioq_blk *qptr; // pointer at i/o queue block
55 struct timeval time; // delay time parameter for select call
56 int sidx = 0; // send index
57
58 errno = EINVAL;
59
60 if( fd < 0 ) {
61 errno = EBADFD;
62 return SI_ERROR; // bad form trying to use this fd
63 }
64
65 if( fd < MAX_FDS ) { // straight from map if possible
66 if ((gptr->tp_map) != NULL) {
67 tpptr = gptr->tp_map[fd];
68 }
69 } else {
70 // list should be locked before traversing
71 for( tpptr = gptr->tplist; tpptr != NULL && tpptr->fd != fd; tpptr = tpptr->next ) ; // find the block if out of map's range
72 }
73 if( tpptr != NULL ) {
74 if( (fd = tpptr->fd) < 0 || (fd = tpptr->fd) >= FD_SETSIZE ) { // fd user given might not be real, and this might be closed already
75 errno = EBADFD;
76 return SI_ERROR;
77 }
78
79 tpptr->sent++; // investigate: this may over count
80
81 FD_ZERO( &writefds ); // clear for select call
82 FD_SET( fd, &writefds ); // set to see if this one was writable
83 FD_ZERO( &execpfds ); // clear and set execptions fdset
84 FD_SET( fd, &execpfds );
85
86 time.tv_sec = 0; // set both to 0 if we just want a poll, else we block at max this amount
87 time.tv_usec = 1; // small pause on check to help drain things