gdbstub: Implement Xfer:auxv:read
PATCH 1/1 gdbstub: Implement Xfer:auxv:read
Implementation of "Xfer:auxv:read" to provide auxiliary vector information to clients which relies on it.
For example: AT_ENTRY in auxiliary vector provides the entry point information. Client can use this information to compare it with entry point mentioned in executable to calculate load offset and then update the load addresses accordingly.
--- gdbstub.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
gdbstub.c +47 -0
@@ -1153,6 +1153,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)if (cc->gdb_core_xml_file !=NULL ) {pstrcat (buf,sizeof (buf),";qXfer:features:read+" ); } +#ifdef CONFIG_USER_ONLY +pstrcat (buf,sizeof (buf),";qXfer:auxv:read+" ); +#endif put_packet (s, buf);break ; }
@@ -1199,6 +1202,50 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)put_packet_binary (s, buf, len +1 );break ; } +#ifdef CONFIG_USER_ONLY +if (strncmp (p,"Xfer:auxv:read:" ,15 ) ==0 ) { +TaskState *ts = s->c_cpu->opaque; +target_ulong auxv = ts->info->saved_auxv; +target_ulong auxv_len = ts->info->auxv_len; +char *ptr; + + p +=15 ; +while (*p && *p !=':' ) { + p++; + } + p++; + + addr =strtoul (p, (char **)&p,16 ); +if (*p ==',' ) { + p++; + } + len =strtoul (p, (char **)&p,16 ); + + ptr =lock_user (VERIFY_READ , auxv, auxv_len,0 ); +if (ptr ==NULL ) { +break ; + } + +if (addr > len) { +snprintf (buf,sizeof (buf),"E00" ); +put_packet (s, buf); +break ; + } +if (len > (MAX_PACKET_LENGTH -5 ) /2 ) { + len = (MAX_PACKET_LENGTH -5 ) /2 ; + } +if (len < auxv_len - addr) { + buf[0 ] ='m' ; + len =memtox (buf +1 , ptr + addr, len); + }else { + buf[0 ] ='l' ; + len =memtox (buf +1 , ptr + addr, auxv_len - addr); + } +put_packet_binary (s, buf, len +1 ); +unlock_user (ptr, auxv, len); +break ; + } +#endif /* !CONFIG_USER_ONLY */ if (is_query_packet (p,"Attached" ,':' )) {put_packet (s,GDB_ATTACHED );break ;
Signature · 1 line
2.4.4
Quoted 60 lines · Bhushan Attarde
Implementation of "Xfer:auxv:read" to provide auxiliary vector information to clients which relies on it.
For example:
AT_ENTRYin auxiliary vector provides the entry point information. Client can use this information to compare it with entry point mentioned in executable to calculate load offset and then update the load addresses accordingly.Signed-off-by Bhushan Attarde <[email protected]>--- gdbstub.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)gdbstub.c +32
-0@@ -1153,6 +1153,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)if (cc->gdb_core_xml_file !=NULL ) {pstrcat (buf,sizeof (buf),";qXfer:features:read+" ); } +#ifdef CONFIG_USER_ONLY +pstrcat (buf,sizeof (buf),";qXfer:auxv:read+" ); +#endif put_packet (s, buf);break ; }@@ -1199,6 +1202,50 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)put_packet_binary (s, buf, len +1 );break ; } +#ifdef CONFIG_USER_ONLY +if (strncmp (p,"Xfer:auxv:read:" ,15 ) ==0 ) { +TaskState *ts = s->c_cpu->opaque; +target_ulong auxv = ts->info->saved_auxv; +target_ulong auxv_len = ts->info->auxv_len; +char *ptr; + + p +=15 ; +while (*p && *p !=':' ) { + p++; + } + p++; + + addr =strtoul (p, (char **)&p,16 ); +if (*p ==',' ) { + p++; + } + len =strtoul (p, (char **)&p,16 ); + + ptr =lock_user (VERIFY_READ , auxv, auxv_len,0 ); +if (ptr ==NULL ) { +break ; + } + +if (addr > len) { +snprintf (buf,sizeof (buf),"E00" ); +put_packet (s, buf); +break ; + }
gdbstub.c static int gdb_handle_packet(GDBState *s, const char *line_buf) · line 1243
Quoted 10 lines
gdbstub.c +10
-0+if (len > (MAX_PACKET_LENGTH -5 ) /2 ) { + len = (MAX_PACKET_LENGTH -5 ) /2 ; + } +if (len < auxv_len - addr) { + buf[0 ] ='m' ; + len =memtox (buf +1 , ptr + addr, len); + }else { + buf[0 ] ='l' ; + len =memtox (buf +1 , ptr + addr, auxv_len - addr); + }
The bulk of this code for parsing out the arguments in a qXfer:OBJECT:read:ANNEX:OFFSET,LENGTH packet is identical to that we already have for handling Xfer:features:read. We should factor this out neatly rather than duplicating it.
thanks
-- PMM