Skip to content

Commit ecc31f7

Browse files
authored
Merge pull request stlink-org#528 from galexander1/k_killrequest
Add 'k' (kill) command to gdb-server, which resets the connection
2 parents e010030 + 9804416 commit ecc31f7

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

src/gdbserver/gdb-server.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ static void cleanup(int signum) {
6969
}
7070

7171

72+
static stlink_t* do_connect(st_state_t *st) {
73+
stlink_t *ret = NULL;
74+
switch (st->stlink_version) {
75+
case 2:
76+
ret = stlink_open_usb(st->logging_level, st->reset, NULL);
77+
break;
78+
case 1:
79+
ret = stlink_v1_open(st->logging_level, st->reset);
80+
break;
81+
}
82+
return ret;
83+
}
84+
7285

7386
int parse_options(int argc, char** argv, st_state_t *st) {
7487
static struct option long_options[] = {
@@ -183,16 +196,8 @@ int main(int argc, char** argv) {
183196

184197
printf("st-util %s\n", STLINK_VERSION);
185198

186-
switch (state.stlink_version) {
187-
case 2:
188-
sl = stlink_open_usb(state.logging_level, state.reset, NULL);
189-
if(sl == NULL) return 1;
190-
break;
191-
case 1:
192-
sl = stlink_v1_open(state.logging_level, state.reset);
193-
if(sl == NULL) return 1;
194-
break;
195-
}
199+
sl = do_connect(&state);
200+
if(sl == NULL) return 1;
196201

197202
connected_stlink = sl;
198203
signal(SIGINT, &cleanup);
@@ -224,6 +229,9 @@ int main(int argc, char** argv) {
224229
sleep (1); // don't go bezurk if serve returns with error
225230
}
226231

232+
/* in case serve() changed the connection */
233+
sl = connected_stlink;
234+
227235
/* Continue */
228236
stlink_run(sl);
229237
} while (state.persistent);
@@ -1671,6 +1679,27 @@ int serve(stlink_t *sl, st_state_t *st) {
16711679

16721680
break;
16731681
}
1682+
case 'k':
1683+
/* Kill request - reset the connection itself */
1684+
stlink_run(sl);
1685+
stlink_exit_debug_mode(sl);
1686+
stlink_close(sl);
1687+
1688+
sl = do_connect(st);
1689+
if(sl == NULL) cleanup(0);
1690+
connected_stlink = sl;
1691+
1692+
if (st->reset) {
1693+
stlink_reset(sl);
1694+
}
1695+
stlink_force_debug(sl);
1696+
init_cache(sl);
1697+
init_code_breakpoints(sl);
1698+
init_data_watchpoints(sl);
1699+
1700+
reply = NULL; /* no response */
1701+
1702+
break;
16741703

16751704
default:
16761705
reply = strdup("");

0 commit comments

Comments
 (0)