63
63
static int phy_memory_mode ;
64
64
#endif
65
65
66
- static inline int target_memory_rw_debug (CPUState * cpu , target_ulong addr ,
66
+
67
+ void (* signal_handler )(int );
68
+ void set_signal_callback (void (* sg )(int )){
69
+ signal_handler = sg ;
70
+ }
71
+
72
+ int target_memory_rw_debug (CPUState * cpu , target_ulong addr ,
67
73
uint8_t * buf , int len , bool is_write )
68
74
{
69
75
CPUClass * cc ;
@@ -377,7 +383,7 @@ typedef struct GDBState {
377
383
static int sstep_flags = SSTEP_ENABLE |SSTEP_NOIRQ |SSTEP_NOTIMER ;
378
384
379
385
/* Retrieves flags for single step mode. */
380
- static int get_sstep_flags (void )
386
+ int get_sstep_flags (void )
381
387
{
382
388
/*
383
389
* In replay mode all events written into the log should be replayed.
@@ -467,7 +473,7 @@ int use_gdb_syscalls(void)
467
473
}
468
474
469
475
/* Resume execution. */
470
- static inline void gdb_continue (void )
476
+ void gdb_continue (void )
471
477
{
472
478
473
479
#ifdef CONFIG_USER_ONLY
@@ -920,7 +926,7 @@ static const char *get_feature_xml(const char *p, const char **newp,
920
926
return name ? xml_builtin [i ][1 ] : NULL ;
921
927
}
922
928
923
- static int gdb_read_register (CPUState * cpu , GByteArray * buf , int reg )
929
+ int gdb_read_register (CPUState * cpu , GByteArray * buf , int reg )
924
930
{
925
931
CPUClass * cc = CPU_GET_CLASS (cpu );
926
932
CPUArchState * env = cpu -> env_ptr ;
@@ -938,7 +944,7 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
938
944
return 0 ;
939
945
}
940
946
941
- static int gdb_write_register (CPUState * cpu , uint8_t * mem_buf , int reg )
947
+ int gdb_write_register (CPUState * cpu , uint8_t * mem_buf , int reg )
942
948
{
943
949
CPUClass * cc = CPU_GET_CLASS (cpu );
944
950
CPUArchState * env = cpu -> env_ptr ;
@@ -1017,7 +1023,7 @@ static inline int xlat_gdb_type(CPUState *cpu, int gdbtype)
1017
1023
}
1018
1024
#endif
1019
1025
1020
- static int gdb_breakpoint_insert (int type , target_ulong addr , target_ulong len )
1026
+ int gdb_breakpoint_insert (int type , target_ulong addr , target_ulong len )
1021
1027
{
1022
1028
CPUState * cpu ;
1023
1029
int err = 0 ;
@@ -1054,7 +1060,7 @@ static int gdb_breakpoint_insert(int type, target_ulong addr, target_ulong len)
1054
1060
}
1055
1061
}
1056
1062
1057
- static int gdb_breakpoint_remove (int type , target_ulong addr , target_ulong len )
1063
+ int gdb_breakpoint_remove (int type , target_ulong addr , target_ulong len )
1058
1064
{
1059
1065
CPUState * cpu ;
1060
1066
int err = 0 ;
@@ -1122,7 +1128,7 @@ static void gdb_breakpoint_remove_all(void)
1122
1128
}
1123
1129
}
1124
1130
1125
- static void gdb_set_cpu_pc (target_ulong pc )
1131
+ void gdb_set_cpu_pc (target_ulong pc )
1126
1132
{
1127
1133
CPUState * cpu = gdbserver_state .c_cpu ;
1128
1134
@@ -3129,49 +3135,66 @@ static void create_default_process(GDBState *s)
3129
3135
}
3130
3136
3131
3137
#ifdef CONFIG_USER_ONLY
3138
+ char dbg [100 ];
3132
3139
int
3133
3140
gdb_handlesig (CPUState * cpu , int sig )
3134
3141
{
3135
- char buf [ 256 ] ;
3136
- int n ;
3142
+ // sprintf(dbg, "sig: %d init: %d fd: %d\n", sig, gdbserver_state.init, gdbserver_state.fd) ;
3143
+ // qemu_plugin_outs(dbg) ;
3137
3144
3138
- if (!gdbserver_state .init || gdbserver_state .fd < 0 ) {
3139
- return sig ;
3145
+ if (signal_handler ){
3146
+ if (sig == GDB_SIGNAL_TRAP ){
3147
+ signal_handler (sig );
3148
+ }
3149
+ else {
3150
+ gdbserver_state .signal = sig ;
3151
+ }
3140
3152
}
3153
+ else {
3141
3154
3142
- /* disable single step if it was enabled */
3143
- cpu_single_step (cpu , 0 );
3144
- tb_flush (cpu );
3155
+ char buf [256 ];
3156
+ int n ;
3145
3157
3146
- if (sig != 0 ) {
3147
- snprintf (buf , sizeof (buf ), "S%02x" , target_signal_to_gdb (sig ));
3148
- put_packet (buf );
3149
- }
3150
- /* put_packet() might have detected that the peer terminated the
3151
- connection. */
3152
- if (gdbserver_state .fd < 0 ) {
3153
- return sig ;
3154
- }
3158
+ if (!gdbserver_state .init || gdbserver_state .fd < 0 ) {
3159
+ return sig ;
3160
+ }
3155
3161
3156
- sig = 0 ;
3157
- gdbserver_state .state = RS_IDLE ;
3158
- gdbserver_state .running_state = 0 ;
3159
- while (gdbserver_state .running_state == 0 ) {
3160
- n = read (gdbserver_state .fd , buf , 256 );
3161
- if (n > 0 ) {
3162
- int i ;
3162
+ /* disable single step if it was enabled */
3163
+ cpu_single_step (cpu , 0 );
3164
+ tb_flush (cpu );
3165
+
3163
3166
3164
- for (i = 0 ; i < n ; i ++ ) {
3165
- gdb_read_byte (buf [i ]);
3167
+ if (sig != 0 ) {
3168
+ snprintf (buf , sizeof (buf ), "S%02x" , target_signal_to_gdb (sig ));
3169
+ put_packet (buf );
3170
+ }
3171
+ /* put_packet() might have detected that the peer terminated the
3172
+ connection. */
3173
+ if (gdbserver_state .fd < 0 ) {
3174
+ return sig ;
3175
+ }
3176
+
3177
+ sig = 0 ;
3178
+ gdbserver_state .state = RS_IDLE ;
3179
+ gdbserver_state .running_state = 0 ;
3180
+ while (gdbserver_state .running_state == 0 ) {
3181
+ n = read (gdbserver_state .fd , buf , 256 );
3182
+ if (n > 0 ) {
3183
+ int i ;
3184
+
3185
+ for (i = 0 ; i < n ; i ++ ) {
3186
+ gdb_read_byte (buf [i ]);
3187
+ }
3166
3188
}
3167
- } else {
3168
- /* XXX: Connection closed. Should probably wait for another
3169
- connection before continuing. */
3170
- if (n == 0 ) {
3171
- close (gdbserver_state .fd );
3189
+ else {
3190
+ /* XXX: Connection closed. Should probably wait for another
3191
+ connection before continuing. */
3192
+ if (n == 0 ) { //Do not close connection if in afl patching mode
3193
+ close (gdbserver_state .fd );
3194
+ }
3195
+ gdbserver_state .fd = -1 ;
3196
+ return sig ;
3172
3197
}
3173
- gdbserver_state .fd = -1 ;
3174
- return sig ;
3175
3198
}
3176
3199
}
3177
3200
sig = gdbserver_state .signal ;
@@ -3192,7 +3215,7 @@ void gdb_signalled(CPUArchState *env, int sig)
3192
3215
put_packet (buf );
3193
3216
}
3194
3217
3195
- static void gdb_accept_init (int fd )
3218
+ void gdb_accept_init (int fd )
3196
3219
{
3197
3220
init_gdbserver_state ();
3198
3221
create_default_process (& gdbserver_state );
@@ -3562,4 +3585,4 @@ static void register_types(void)
3562
3585
}
3563
3586
3564
3587
type_init (register_types );
3565
- #endif
3588
+ #endif
0 commit comments