gdbstub.c (534af1082329392bc29f6badf815e69ae2ae0f4c) | gdbstub.c (55751145dc1e08e16df418cdd101661f5c6ac991) |
---|---|
1/* 2 * Kernel Debug Core 3 * 4 * Maintainer: Jason Wessel <jason.wessel@windriver.com> 5 * 6 * Copyright (C) 2000-2001 VERITAS Software Corporation. 7 * Copyright (C) 2002-2004 Timesys Corporation 8 * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> --- 211 unchanged lines hidden (view full) --- 220 } 221} 222 223/* 224 * Convert the memory pointed to by mem into hex, placing result in 225 * buf. Return a pointer to the last char put in buf (null). May 226 * return an error. 227 */ | 1/* 2 * Kernel Debug Core 3 * 4 * Maintainer: Jason Wessel <jason.wessel@windriver.com> 5 * 6 * Copyright (C) 2000-2001 VERITAS Software Corporation. 7 * Copyright (C) 2002-2004 Timesys Corporation 8 * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> --- 211 unchanged lines hidden (view full) --- 220 } 221} 222 223/* 224 * Convert the memory pointed to by mem into hex, placing result in 225 * buf. Return a pointer to the last char put in buf (null). May 226 * return an error. 227 */ |
228int kgdb_mem2hex(char *mem, char *buf, int count) | 228char *kgdb_mem2hex(char *mem, char *buf, int count) |
229{ 230 char *tmp; 231 int err; 232 233 /* 234 * We use the upper half of buf as an intermediate buffer for the 235 * raw memory copy. Hex conversion will work against this one. 236 */ 237 tmp = buf + count; 238 239 err = probe_kernel_read(tmp, mem, count); | 229{ 230 char *tmp; 231 int err; 232 233 /* 234 * We use the upper half of buf as an intermediate buffer for the 235 * raw memory copy. Hex conversion will work against this one. 236 */ 237 tmp = buf + count; 238 239 err = probe_kernel_read(tmp, mem, count); |
240 if (!err) { 241 while (count > 0) { 242 buf = pack_hex_byte(buf, *tmp); 243 tmp++; 244 count--; 245 } 246 247 *buf = 0; | 240 if (err) 241 return NULL; 242 while (count > 0) { 243 buf = pack_hex_byte(buf, *tmp); 244 tmp++; 245 count--; |
248 } | 246 } |
247 *buf = 0; |
|
249 | 248 |
250 return err; | 249 return buf; |
251} 252 253/* 254 * Convert the hex array pointed to by buf into binary to be placed in 255 * mem. Return a pointer to the character AFTER the last byte 256 * written. May return an error. 257 */ 258int kgdb_hex2mem(char *buf, char *mem, int count) --- 217 unchanged lines hidden (view full) --- 476 * GDB is reconnecting. 477 */ 478 dbg_remove_all_break(); 479 480 remcom_out_buffer[0] = 'S'; 481 pack_hex_byte(&remcom_out_buffer[1], ks->signo); 482} 483 | 250} 251 252/* 253 * Convert the hex array pointed to by buf into binary to be placed in 254 * mem. Return a pointer to the character AFTER the last byte 255 * written. May return an error. 256 */ 257int kgdb_hex2mem(char *buf, char *mem, int count) --- 217 unchanged lines hidden (view full) --- 475 * GDB is reconnecting. 476 */ 477 dbg_remove_all_break(); 478 479 remcom_out_buffer[0] = 'S'; 480 pack_hex_byte(&remcom_out_buffer[1], ks->signo); 481} 482 |
484/* Handle the 'g' get registers request */ 485static void gdb_cmd_getregs(struct kgdb_state *ks) | 483static void gdb_get_regs_helper(struct kgdb_state *ks) |
486{ 487 struct task_struct *thread; 488 void *local_debuggerinfo; 489 int i; 490 491 thread = kgdb_usethread; 492 if (!thread) { 493 thread = kgdb_info[ks->cpu].task; --- 24 unchanged lines hidden (view full) --- 518 * Pull stuff saved during switch_to; nothing 519 * else is accessible (or even particularly 520 * relevant). 521 * 522 * This should be enough for a stack trace. 523 */ 524 sleeping_thread_to_gdb_regs(gdb_regs, thread); 525 } | 484{ 485 struct task_struct *thread; 486 void *local_debuggerinfo; 487 int i; 488 489 thread = kgdb_usethread; 490 if (!thread) { 491 thread = kgdb_info[ks->cpu].task; --- 24 unchanged lines hidden (view full) --- 516 * Pull stuff saved during switch_to; nothing 517 * else is accessible (or even particularly 518 * relevant). 519 * 520 * This should be enough for a stack trace. 521 */ 522 sleeping_thread_to_gdb_regs(gdb_regs, thread); 523 } |
524} 525 526/* Handle the 'g' get registers request */ 527static void gdb_cmd_getregs(struct kgdb_state *ks) 528{ 529 gdb_get_regs_helper(ks); |
|
526 kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES); 527} 528 529/* Handle the 'G' set registers request */ 530static void gdb_cmd_setregs(struct kgdb_state *ks) 531{ 532 kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES); 533 --- 6 unchanged lines hidden (view full) --- 540} 541 542/* Handle the 'm' memory read bytes */ 543static void gdb_cmd_memread(struct kgdb_state *ks) 544{ 545 char *ptr = &remcom_in_buffer[1]; 546 unsigned long length; 547 unsigned long addr; | 530 kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES); 531} 532 533/* Handle the 'G' set registers request */ 534static void gdb_cmd_setregs(struct kgdb_state *ks) 535{ 536 kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES); 537 --- 6 unchanged lines hidden (view full) --- 544} 545 546/* Handle the 'm' memory read bytes */ 547static void gdb_cmd_memread(struct kgdb_state *ks) 548{ 549 char *ptr = &remcom_in_buffer[1]; 550 unsigned long length; 551 unsigned long addr; |
548 int err; | 552 char *err; |
549 550 if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' && 551 kgdb_hex2long(&ptr, &length) > 0) { 552 err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length); | 553 554 if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' && 555 kgdb_hex2long(&ptr, &length) > 0) { 556 err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length); |
553 if (err) 554 error_packet(remcom_out_buffer, err); | 557 if (!err) 558 error_packet(remcom_out_buffer, -EINVAL); |
555 } else { 556 error_packet(remcom_out_buffer, -EINVAL); 557 } 558} 559 560/* Handle the 'M' memory write bytes */ 561static void gdb_cmd_memwrite(struct kgdb_state *ks) 562{ 563 int err = write_mem_msg(0); 564 565 if (err) 566 error_packet(remcom_out_buffer, err); 567 else 568 strcpy(remcom_out_buffer, "OK"); 569} 570 | 559 } else { 560 error_packet(remcom_out_buffer, -EINVAL); 561 } 562} 563 564/* Handle the 'M' memory write bytes */ 565static void gdb_cmd_memwrite(struct kgdb_state *ks) 566{ 567 int err = write_mem_msg(0); 568 569 if (err) 570 error_packet(remcom_out_buffer, err); 571 else 572 strcpy(remcom_out_buffer, "OK"); 573} 574 |
575#if DBG_MAX_REG_NUM > 0 576static char *gdb_hex_reg_helper(int regnum, char *out) 577{ 578 int i; 579 int offset = 0; 580 581 for (i = 0; i < regnum; i++) 582 offset += dbg_reg_def[i].size; 583 return kgdb_mem2hex((char *)gdb_regs + offset, out, 584 dbg_reg_def[i].size); 585} 586 587/* Handle the 'p' individual regster get */ 588static void gdb_cmd_reg_get(struct kgdb_state *ks) 589{ 590 unsigned long regnum; 591 char *ptr = &remcom_in_buffer[1]; 592 593 kgdb_hex2long(&ptr, ®num); 594 if (regnum >= DBG_MAX_REG_NUM) { 595 error_packet(remcom_out_buffer, -EINVAL); 596 return; 597 } 598 gdb_get_regs_helper(ks); 599 gdb_hex_reg_helper(regnum, remcom_out_buffer); 600} 601 602/* Handle the 'P' individual regster set */ 603static void gdb_cmd_reg_set(struct kgdb_state *ks) 604{ 605 unsigned long regnum; 606 char *ptr = &remcom_in_buffer[1]; 607 608 kgdb_hex2long(&ptr, ®num); 609 if (*ptr++ != '=' || 610 !(!kgdb_usethread || kgdb_usethread == current) || 611 !dbg_get_reg(regnum, gdb_regs, ks->linux_regs)) { 612 error_packet(remcom_out_buffer, -EINVAL); 613 return; 614 } 615 kgdb_hex2mem(ptr, (char *)gdb_regs, dbg_reg_def[regnum].size); 616 dbg_set_reg(regnum, gdb_regs, ks->linux_regs); 617 strcpy(remcom_out_buffer, "OK"); 618} 619#endif /* DBG_MAX_REG_NUM > 0 */ 620 |
|
571/* Handle the 'X' memory binary write bytes */ 572static void gdb_cmd_binwrite(struct kgdb_state *ks) 573{ 574 int err = write_mem_msg(1); 575 576 if (err) 577 error_packet(remcom_out_buffer, err); 578 else --- 290 unchanged lines hidden (view full) --- 869/* 870 * This function performs all gdbserial command procesing 871 */ 872int gdb_serial_stub(struct kgdb_state *ks) 873{ 874 int error = 0; 875 int tmp; 876 | 621/* Handle the 'X' memory binary write bytes */ 622static void gdb_cmd_binwrite(struct kgdb_state *ks) 623{ 624 int err = write_mem_msg(1); 625 626 if (err) 627 error_packet(remcom_out_buffer, err); 628 else --- 290 unchanged lines hidden (view full) --- 919/* 920 * This function performs all gdbserial command procesing 921 */ 922int gdb_serial_stub(struct kgdb_state *ks) 923{ 924 int error = 0; 925 int tmp; 926 |
877 /* Clear the out buffer. */ | 927 /* Initialize comm buffer and globals. */ |
878 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); | 928 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); |
929 kgdb_usethread = kgdb_info[ks->cpu].task; 930 ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid); 931 ks->pass_exception = 0; |
|
879 880 if (kgdb_connected) { 881 unsigned char thref[BUF_THREAD_ID_SIZE]; 882 char *ptr; 883 884 /* Reply to host that an exception has occurred */ 885 ptr = remcom_out_buffer; 886 *ptr++ = 'T'; 887 ptr = pack_hex_byte(ptr, ks->signo); 888 ptr += strlen(strcpy(ptr, "thread:")); 889 int_to_threadref(thref, shadow_pid(current->pid)); 890 ptr = pack_threadid(ptr, thref); 891 *ptr++ = ';'; 892 put_packet(remcom_out_buffer); 893 } 894 | 932 933 if (kgdb_connected) { 934 unsigned char thref[BUF_THREAD_ID_SIZE]; 935 char *ptr; 936 937 /* Reply to host that an exception has occurred */ 938 ptr = remcom_out_buffer; 939 *ptr++ = 'T'; 940 ptr = pack_hex_byte(ptr, ks->signo); 941 ptr += strlen(strcpy(ptr, "thread:")); 942 int_to_threadref(thref, shadow_pid(current->pid)); 943 ptr = pack_threadid(ptr, thref); 944 *ptr++ = ';'; 945 put_packet(remcom_out_buffer); 946 } 947 |
895 kgdb_usethread = kgdb_info[ks->cpu].task; 896 ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid); 897 ks->pass_exception = 0; 898 | |
899 while (1) { 900 error = 0; 901 902 /* Clear the out buffer. */ 903 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); 904 905 get_packet(remcom_in_buffer); 906 --- 8 unchanged lines hidden (view full) --- 915 gdb_cmd_setregs(ks); 916 break; 917 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ 918 gdb_cmd_memread(ks); 919 break; 920 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */ 921 gdb_cmd_memwrite(ks); 922 break; | 948 while (1) { 949 error = 0; 950 951 /* Clear the out buffer. */ 952 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); 953 954 get_packet(remcom_in_buffer); 955 --- 8 unchanged lines hidden (view full) --- 964 gdb_cmd_setregs(ks); 965 break; 966 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ 967 gdb_cmd_memread(ks); 968 break; 969 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */ 970 gdb_cmd_memwrite(ks); 971 break; |
972#if DBG_MAX_REG_NUM > 0 973 case 'p': /* pXX Return gdb register XX (in hex) */ 974 gdb_cmd_reg_get(ks); 975 break; 976 case 'P': /* PXX=aaaa Set gdb register XX to aaaa (in hex) */ 977 gdb_cmd_reg_set(ks); 978 break; 979#endif /* DBG_MAX_REG_NUM > 0 */ |
|
923 case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */ 924 gdb_cmd_binwrite(ks); 925 break; 926 /* kill or detach. KGDB should treat this like a 927 * continue. 928 */ 929 case 'D': /* Debugger detach */ 930 case 'k': /* Debugger detach via kill */ --- 100 unchanged lines hidden --- | 980 case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */ 981 gdb_cmd_binwrite(ks); 982 break; 983 /* kill or detach. KGDB should treat this like a 984 * continue. 985 */ 986 case 'D': /* Debugger detach */ 987 case 'k': /* Debugger detach via kill */ --- 100 unchanged lines hidden --- |