forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.c
4479 lines (3748 loc) · 109 KB
/
server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Main code for remote server for GDB.
Copyright (C) 1989-2016 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "server.h"
#include "gdbthread.h"
#include "agent.h"
#include "notif.h"
#include "tdesc.h"
#include "rsp-low.h"
#include "signals-state-save-restore.h"
#include <ctype.h>
#include <unistd.h>
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#include "gdb_vecs.h"
#include "gdb_wait.h"
#include "btrace-common.h"
#include "filestuff.h"
#include "tracepoint.h"
#include "dll.h"
#include "hostio.h"
/* The thread set with an `Hc' packet. `Hc' is deprecated in favor of
`vCont'. Note the multi-process extensions made `vCont' a
requirement, so `Hc pPID.TID' is pretty much undefined. So
CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for
resuming all threads of the process (again, `Hc' isn't used for
multi-process), or a specific thread ptid_t. */
ptid_t cont_thread;
/* The thread set with an `Hg' packet. */
ptid_t general_thread;
int server_waiting;
static int extended_protocol;
static int response_needed;
static int exit_requested;
/* --once: Exit after the first connection has closed. */
int run_once;
int multi_process;
int report_fork_events;
int report_vfork_events;
int report_exec_events;
int report_thread_events;
/* Whether to report TARGET_WAITKING_NO_RESUMED events. */
static int report_no_resumed;
int non_stop;
int swbreak_feature;
int hwbreak_feature;
/* True if the "vContSupported" feature is active. In that case, GDB
wants us to report whether single step is supported in the reply to
"vCont?" packet. */
static int vCont_supported;
/* Whether we should attempt to disable the operating system's address
space randomization feature before starting an inferior. */
int disable_randomization = 1;
static char **program_argv, **wrapper_argv;
int pass_signals[GDB_SIGNAL_LAST];
int program_signals[GDB_SIGNAL_LAST];
int program_signals_p;
/* The PID of the originally created or attached inferior. Used to
send signals to the process when GDB sends us an asynchronous interrupt
(user hitting Control-C in the client), and to wait for the child to exit
when no longer debugging it. */
unsigned long signal_pid;
#ifdef SIGTTOU
/* A file descriptor for the controlling terminal. */
int terminal_fd;
/* TERMINAL_FD's original foreground group. */
pid_t old_foreground_pgrp;
/* Hand back terminal ownership to the original foreground group. */
static void
restore_old_foreground_pgrp (void)
{
tcsetpgrp (terminal_fd, old_foreground_pgrp);
}
#endif
/* Set if you want to disable optional thread related packets support
in gdbserver, for the sake of testing GDB against stubs that don't
support them. */
int disable_packet_vCont;
int disable_packet_Tthread;
int disable_packet_qC;
int disable_packet_qfThreadInfo;
/* Last status reported to GDB. */
static struct target_waitstatus last_status;
static ptid_t last_ptid;
char *own_buf;
static unsigned char *mem_buf;
/* A sub-class of 'struct notif_event' for stop, holding information
relative to a single stop reply. We keep a queue of these to
push to GDB in non-stop mode. */
struct vstop_notif
{
struct notif_event base;
/* Thread or process that got the event. */
ptid_t ptid;
/* Event info. */
struct target_waitstatus status;
};
/* The current btrace configuration. This is gdbserver's mirror of GDB's
btrace configuration. */
static struct btrace_config current_btrace_conf;
DEFINE_QUEUE_P (notif_event_p);
/* Put a stop reply to the stop reply queue. */
static void
queue_stop_reply (ptid_t ptid, struct target_waitstatus *status)
{
struct vstop_notif *new_notif = XNEW (struct vstop_notif);
new_notif->ptid = ptid;
new_notif->status = *status;
notif_event_enque (¬if_stop, (struct notif_event *) new_notif);
}
static int
remove_all_on_match_ptid (QUEUE (notif_event_p) *q,
QUEUE_ITER (notif_event_p) *iter,
struct notif_event *event,
void *data)
{
ptid_t filter_ptid = *(ptid_t *) data;
struct vstop_notif *vstop_event = (struct vstop_notif *) event;
if (ptid_match (vstop_event->ptid, filter_ptid))
{
if (q->free_func != NULL)
q->free_func (event);
QUEUE_remove_elem (notif_event_p, q, iter);
}
return 1;
}
/* See server.h. */
void
discard_queued_stop_replies (ptid_t ptid)
{
QUEUE_iterate (notif_event_p, notif_stop.queue,
remove_all_on_match_ptid, &ptid);
}
static void
vstop_notif_reply (struct notif_event *event, char *own_buf)
{
struct vstop_notif *vstop = (struct vstop_notif *) event;
prepare_resume_reply (own_buf, vstop->ptid, &vstop->status);
}
/* QUEUE_iterate callback helper for in_queued_stop_replies. */
static int
in_queued_stop_replies_ptid (QUEUE (notif_event_p) *q,
QUEUE_ITER (notif_event_p) *iter,
struct notif_event *event,
void *data)
{
ptid_t filter_ptid = *(ptid_t *) data;
struct vstop_notif *vstop_event = (struct vstop_notif *) event;
if (ptid_match (vstop_event->ptid, filter_ptid))
return 0;
/* Don't resume fork children that GDB does not know about yet. */
if ((vstop_event->status.kind == TARGET_WAITKIND_FORKED
|| vstop_event->status.kind == TARGET_WAITKIND_VFORKED)
&& ptid_match (vstop_event->status.value.related_pid, filter_ptid))
return 0;
return 1;
}
/* See server.h. */
int
in_queued_stop_replies (ptid_t ptid)
{
return !QUEUE_iterate (notif_event_p, notif_stop.queue,
in_queued_stop_replies_ptid, &ptid);
}
struct notif_server notif_stop =
{
"vStopped", "Stop", NULL, vstop_notif_reply,
};
static int
target_running (void)
{
return get_first_thread () != NULL;
}
static int
start_inferior (char **argv)
{
char **new_argv = argv;
if (wrapper_argv != NULL)
{
int i, count = 1;
for (i = 0; wrapper_argv[i] != NULL; i++)
count++;
for (i = 0; argv[i] != NULL; i++)
count++;
new_argv = XALLOCAVEC (char *, count);
count = 0;
for (i = 0; wrapper_argv[i] != NULL; i++)
new_argv[count++] = wrapper_argv[i];
for (i = 0; argv[i] != NULL; i++)
new_argv[count++] = argv[i];
new_argv[count] = NULL;
}
if (debug_threads)
{
int i;
for (i = 0; new_argv[i]; ++i)
debug_printf ("new_argv[%d] = \"%s\"\n", i, new_argv[i]);
debug_flush ();
}
#ifdef SIGTTOU
signal (SIGTTOU, SIG_DFL);
signal (SIGTTIN, SIG_DFL);
#endif
signal_pid = create_inferior (new_argv[0], new_argv);
/* FIXME: we don't actually know at this point that the create
actually succeeded. We won't know that until we wait. */
fprintf (stderr, "Process %s created; pid = %ld\n", argv[0],
signal_pid);
fflush (stderr);
#ifdef SIGTTOU
signal (SIGTTOU, SIG_IGN);
signal (SIGTTIN, SIG_IGN);
terminal_fd = fileno (stderr);
old_foreground_pgrp = tcgetpgrp (terminal_fd);
tcsetpgrp (terminal_fd, signal_pid);
atexit (restore_old_foreground_pgrp);
#endif
if (wrapper_argv != NULL)
{
ptid_t ptid = pid_to_ptid (signal_pid);
last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
if (last_status.kind == TARGET_WAITKIND_STOPPED)
{
do
{
target_continue_no_signal (ptid);
last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
if (last_status.kind != TARGET_WAITKIND_STOPPED)
break;
current_thread->last_resume_kind = resume_stop;
current_thread->last_status = last_status;
}
while (last_status.value.sig != GDB_SIGNAL_TRAP);
}
target_post_create_inferior ();
return signal_pid;
}
/* Wait till we are at 1st instruction in program, return new pid
(assuming success). */
last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
/* At this point, the target process, if it exits, is stopped. Do not call
the function target_post_create_inferior if the process has already
exited, as the target implementation of the routine may rely on the
process being live. */
if (last_status.kind != TARGET_WAITKIND_EXITED
&& last_status.kind != TARGET_WAITKIND_SIGNALLED)
{
target_post_create_inferior ();
current_thread->last_resume_kind = resume_stop;
current_thread->last_status = last_status;
}
else
target_mourn_inferior (last_ptid);
return signal_pid;
}
static int
attach_inferior (int pid)
{
/* myattach should return -1 if attaching is unsupported,
0 if it succeeded, and call error() otherwise. */
if (myattach (pid) != 0)
return -1;
fprintf (stderr, "Attached; pid = %d\n", pid);
fflush (stderr);
/* FIXME - It may be that we should get the SIGNAL_PID from the
attach function, so that it can be the main thread instead of
whichever we were told to attach to. */
signal_pid = pid;
if (!non_stop)
{
last_ptid = mywait (pid_to_ptid (pid), &last_status, 0, 0);
/* GDB knows to ignore the first SIGSTOP after attaching to a running
process using the "attach" command, but this is different; it's
just using "target remote". Pretend it's just starting up. */
if (last_status.kind == TARGET_WAITKIND_STOPPED
&& last_status.value.sig == GDB_SIGNAL_STOP)
last_status.value.sig = GDB_SIGNAL_TRAP;
current_thread->last_resume_kind = resume_stop;
current_thread->last_status = last_status;
}
return 0;
}
extern int remote_debug;
/* Decode a qXfer read request. Return 0 if everything looks OK,
or -1 otherwise. */
static int
decode_xfer_read (char *buf, CORE_ADDR *ofs, unsigned int *len)
{
/* After the read marker and annex, qXfer looks like a
traditional 'm' packet. */
decode_m_packet (buf, ofs, len);
return 0;
}
static int
decode_xfer (char *buf, char **object, char **rw, char **annex, char **offset)
{
/* Extract and NUL-terminate the object. */
*object = buf;
while (*buf && *buf != ':')
buf++;
if (*buf == '\0')
return -1;
*buf++ = 0;
/* Extract and NUL-terminate the read/write action. */
*rw = buf;
while (*buf && *buf != ':')
buf++;
if (*buf == '\0')
return -1;
*buf++ = 0;
/* Extract and NUL-terminate the annex. */
*annex = buf;
while (*buf && *buf != ':')
buf++;
if (*buf == '\0')
return -1;
*buf++ = 0;
*offset = buf;
return 0;
}
/* Write the response to a successful qXfer read. Returns the
length of the (binary) data stored in BUF, corresponding
to as much of DATA/LEN as we could fit. IS_MORE controls
the first character of the response. */
static int
write_qxfer_response (char *buf, const gdb_byte *data, int len, int is_more)
{
int out_len;
if (is_more)
buf[0] = 'm';
else
buf[0] = 'l';
return remote_escape_output (data, len, 1, (unsigned char *) buf + 1,
&out_len, PBUFSIZ - 2) + 1;
}
/* Handle btrace enabling in BTS format. */
static const char *
handle_btrace_enable_bts (struct thread_info *thread)
{
if (thread->btrace != NULL)
return "E.Btrace already enabled.";
current_btrace_conf.format = BTRACE_FORMAT_BTS;
thread->btrace = target_enable_btrace (thread->entry.id,
¤t_btrace_conf);
if (thread->btrace == NULL)
return "E.Could not enable btrace.";
return NULL;
}
/* Handle btrace enabling in Intel Processor Trace format. */
static const char *
handle_btrace_enable_pt (struct thread_info *thread)
{
if (thread->btrace != NULL)
return "E.Btrace already enabled.";
current_btrace_conf.format = BTRACE_FORMAT_PT;
thread->btrace = target_enable_btrace (thread->entry.id,
¤t_btrace_conf);
if (thread->btrace == NULL)
return "E.Could not enable btrace.";
return NULL;
}
/* Handle btrace disabling. */
static const char *
handle_btrace_disable (struct thread_info *thread)
{
if (thread->btrace == NULL)
return "E.Branch tracing not enabled.";
if (target_disable_btrace (thread->btrace) != 0)
return "E.Could not disable branch tracing.";
thread->btrace = NULL;
return NULL;
}
/* Handle the "Qbtrace" packet. */
static int
handle_btrace_general_set (char *own_buf)
{
struct thread_info *thread;
const char *err;
char *op;
if (!startswith (own_buf, "Qbtrace:"))
return 0;
op = own_buf + strlen ("Qbtrace:");
if (ptid_equal (general_thread, null_ptid)
|| ptid_equal (general_thread, minus_one_ptid))
{
strcpy (own_buf, "E.Must select a single thread.");
return -1;
}
thread = find_thread_ptid (general_thread);
if (thread == NULL)
{
strcpy (own_buf, "E.No such thread.");
return -1;
}
err = NULL;
if (strcmp (op, "bts") == 0)
err = handle_btrace_enable_bts (thread);
else if (strcmp (op, "pt") == 0)
err = handle_btrace_enable_pt (thread);
else if (strcmp (op, "off") == 0)
err = handle_btrace_disable (thread);
else
err = "E.Bad Qbtrace operation. Use bts, pt, or off.";
if (err != 0)
strcpy (own_buf, err);
else
write_ok (own_buf);
return 1;
}
/* Handle the "Qbtrace-conf" packet. */
static int
handle_btrace_conf_general_set (char *own_buf)
{
struct thread_info *thread;
char *op;
if (!startswith (own_buf, "Qbtrace-conf:"))
return 0;
op = own_buf + strlen ("Qbtrace-conf:");
if (ptid_equal (general_thread, null_ptid)
|| ptid_equal (general_thread, minus_one_ptid))
{
strcpy (own_buf, "E.Must select a single thread.");
return -1;
}
thread = find_thread_ptid (general_thread);
if (thread == NULL)
{
strcpy (own_buf, "E.No such thread.");
return -1;
}
if (startswith (op, "bts:size="))
{
unsigned long size;
char *endp = NULL;
errno = 0;
size = strtoul (op + strlen ("bts:size="), &endp, 16);
if (endp == NULL || *endp != 0 || errno != 0 || size > UINT_MAX)
{
strcpy (own_buf, "E.Bad size value.");
return -1;
}
current_btrace_conf.bts.size = (unsigned int) size;
}
else if (strncmp (op, "pt:size=", strlen ("pt:size=")) == 0)
{
unsigned long size;
char *endp = NULL;
errno = 0;
size = strtoul (op + strlen ("pt:size="), &endp, 16);
if (endp == NULL || *endp != 0 || errno != 0 || size > UINT_MAX)
{
strcpy (own_buf, "E.Bad size value.");
return -1;
}
current_btrace_conf.pt.size = (unsigned int) size;
}
else
{
strcpy (own_buf, "E.Bad Qbtrace configuration option.");
return -1;
}
write_ok (own_buf);
return 1;
}
/* Handle all of the extended 'Q' packets. */
static void
handle_general_set (char *own_buf)
{
if (startswith (own_buf, "QPassSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QPassSignals:");
CORE_ADDR cursig;
p = decode_address_to_semicolon (&cursig, p);
for (i = 0; i < numsigs; i++)
{
if (i == cursig)
{
pass_signals[i] = 1;
if (*p == '\0')
/* Keep looping, to clear the remaining signals. */
cursig = -1;
else
p = decode_address_to_semicolon (&cursig, p);
}
else
pass_signals[i] = 0;
}
strcpy (own_buf, "OK");
return;
}
if (startswith (own_buf, "QProgramSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QProgramSignals:");
CORE_ADDR cursig;
program_signals_p = 1;
p = decode_address_to_semicolon (&cursig, p);
for (i = 0; i < numsigs; i++)
{
if (i == cursig)
{
program_signals[i] = 1;
if (*p == '\0')
/* Keep looping, to clear the remaining signals. */
cursig = -1;
else
p = decode_address_to_semicolon (&cursig, p);
}
else
program_signals[i] = 0;
}
strcpy (own_buf, "OK");
return;
}
if (startswith (own_buf, "QCatchSyscalls:"))
{
const char *p = own_buf + sizeof ("QCatchSyscalls:") - 1;
int enabled = -1;
CORE_ADDR sysno;
struct process_info *process;
if (!target_running () || !target_supports_catch_syscall ())
{
write_enn (own_buf);
return;
}
if (strcmp (p, "0") == 0)
enabled = 0;
else if (p[0] == '1' && (p[1] == ';' || p[1] == '\0'))
enabled = 1;
else
{
fprintf (stderr, "Unknown catch-syscalls mode requested: %s\n",
own_buf);
write_enn (own_buf);
return;
}
process = current_process ();
VEC_truncate (int, process->syscalls_to_catch, 0);
if (enabled)
{
p += 1;
if (*p == ';')
{
p += 1;
while (*p != '\0')
{
p = decode_address_to_semicolon (&sysno, p);
VEC_safe_push (int, process->syscalls_to_catch, (int) sysno);
}
}
else
VEC_safe_push (int, process->syscalls_to_catch, ANY_SYSCALL);
}
write_ok (own_buf);
return;
}
if (strcmp (own_buf, "QStartNoAckMode") == 0)
{
if (remote_debug)
{
debug_printf ("[noack mode enabled]\n");
debug_flush ();
}
noack_mode = 1;
write_ok (own_buf);
return;
}
if (startswith (own_buf, "QNonStop:"))
{
char *mode = own_buf + 9;
int req = -1;
const char *req_str;
if (strcmp (mode, "0") == 0)
req = 0;
else if (strcmp (mode, "1") == 0)
req = 1;
else
{
/* We don't know what this mode is, so complain to
GDB. */
fprintf (stderr, "Unknown non-stop mode requested: %s\n",
own_buf);
write_enn (own_buf);
return;
}
req_str = req ? "non-stop" : "all-stop";
if (start_non_stop (req) != 0)
{
fprintf (stderr, "Setting %s mode failed\n", req_str);
write_enn (own_buf);
return;
}
non_stop = req;
if (remote_debug)
debug_printf ("[%s mode enabled]\n", req_str);
write_ok (own_buf);
return;
}
if (startswith (own_buf, "QDisableRandomization:"))
{
char *packet = own_buf + strlen ("QDisableRandomization:");
ULONGEST setting;
unpack_varlen_hex (packet, &setting);
disable_randomization = setting;
if (remote_debug)
{
debug_printf (disable_randomization
? "[address space randomization disabled]\n"
: "[address space randomization enabled]\n");
}
write_ok (own_buf);
return;
}
if (target_supports_tracepoints ()
&& handle_tracepoint_general_set (own_buf))
return;
if (startswith (own_buf, "QAgent:"))
{
char *mode = own_buf + strlen ("QAgent:");
int req = 0;
if (strcmp (mode, "0") == 0)
req = 0;
else if (strcmp (mode, "1") == 0)
req = 1;
else
{
/* We don't know what this value is, so complain to GDB. */
sprintf (own_buf, "E.Unknown QAgent value");
return;
}
/* Update the flag. */
use_agent = req;
if (remote_debug)
debug_printf ("[%s agent]\n", req ? "Enable" : "Disable");
write_ok (own_buf);
return;
}
if (handle_btrace_general_set (own_buf))
return;
if (handle_btrace_conf_general_set (own_buf))
return;
if (startswith (own_buf, "QThreadEvents:"))
{
char *mode = own_buf + strlen ("QThreadEvents:");
enum tribool req = TRIBOOL_UNKNOWN;
if (strcmp (mode, "0") == 0)
req = TRIBOOL_FALSE;
else if (strcmp (mode, "1") == 0)
req = TRIBOOL_TRUE;
else
{
char *mode_copy = xstrdup (mode);
/* We don't know what this mode is, so complain to GDB. */
sprintf (own_buf, "E.Unknown thread-events mode requested: %s\n",
mode_copy);
xfree (mode_copy);
return;
}
report_thread_events = (req == TRIBOOL_TRUE);
if (remote_debug)
{
const char *req_str = report_thread_events ? "enabled" : "disabled";
debug_printf ("[thread events are now %s]\n", req_str);
}
write_ok (own_buf);
return;
}
/* Otherwise we didn't know what packet it was. Say we didn't
understand it. */
own_buf[0] = 0;
}
static const char *
get_features_xml (const char *annex)
{
const struct target_desc *desc = current_target_desc ();
/* `desc->xmltarget' defines what to return when looking for the
"target.xml" file. Its contents can either be verbatim XML code
(prefixed with a '@') or else the name of the actual XML file to
be used in place of "target.xml".
This variable is set up from the auto-generated
init_registers_... routine for the current target. */
if (desc->xmltarget != NULL && strcmp (annex, "target.xml") == 0)
{
if (*desc->xmltarget == '@')
return desc->xmltarget + 1;
else
annex = desc->xmltarget;
}
#ifdef USE_XML
{
extern const char *const xml_builtin[][2];
int i;
/* Look for the annex. */
for (i = 0; xml_builtin[i][0] != NULL; i++)
if (strcmp (annex, xml_builtin[i][0]) == 0)
break;
if (xml_builtin[i][0] != NULL)
return xml_builtin[i][1];
}
#endif
return NULL;
}
static void
monitor_show_help (void)
{
monitor_output ("The following monitor commands are supported:\n");
monitor_output (" set debug <0|1>\n");
monitor_output (" Enable general debugging messages\n");
monitor_output (" set debug-hw-points <0|1>\n");
monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
monitor_output (" set remote-debug <0|1>\n");
monitor_output (" Enable remote protocol debugging messages\n");
monitor_output (" set debug-format option1[,option2,...]\n");
monitor_output (" Add additional information to debugging messages\n");
monitor_output (" Options: all, none");
monitor_output (", timestamp");
monitor_output ("\n");
monitor_output (" exit\n");
monitor_output (" Quit GDBserver\n");
}
/* Read trace frame or inferior memory. Returns the number of bytes
actually read, zero when no further transfer is possible, and -1 on
error. Return of a positive value smaller than LEN does not
indicate there's no more to be read, only the end of the transfer.
E.g., when GDB reads memory from a traceframe, a first request may
be served from a memory block that does not cover the whole request
length. A following request gets the rest served from either
another block (of the same traceframe) or from the read-only
regions. */
static int
gdb_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
{
int res;
if (current_traceframe >= 0)
{
ULONGEST nbytes;
ULONGEST length = len;
if (traceframe_read_mem (current_traceframe,
memaddr, myaddr, len, &nbytes))
return -1;
/* Data read from trace buffer, we're done. */
if (nbytes > 0)
return nbytes;
if (!in_readonly_region (memaddr, length))
return -1;
/* Otherwise we have a valid readonly case, fall through. */
/* (assume no half-trace half-real blocks for now) */
}
res = prepare_to_access_memory ();
if (res == 0)
{
if (set_desired_thread (1))
res = read_inferior_memory (memaddr, myaddr, len);
else
res = 1;
done_accessing_memory ();
return res == 0 ? len : -1;
}
else
return -1;
}
/* Write trace frame or inferior memory. Actually, writing to trace
frames is forbidden. */
static int
gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
{
if (current_traceframe >= 0)
return EIO;
else
{
int ret;
ret = prepare_to_access_memory ();
if (ret == 0)
{
if (set_desired_thread (1))
ret = write_inferior_memory (memaddr, myaddr, len);
else
ret = EIO;
done_accessing_memory ();
}
return ret;
}
}
/* Subroutine of handle_search_memory to simplify it. */
static int
handle_search_memory_1 (CORE_ADDR start_addr, CORE_ADDR search_space_len,
gdb_byte *pattern, unsigned pattern_len,
gdb_byte *search_buf,
unsigned chunk_size, unsigned search_buf_size,
CORE_ADDR *found_addrp)
{
/* Prime the search buffer. */
if (gdb_read_memory (start_addr, search_buf, search_buf_size)
!= search_buf_size)
{
warning ("Unable to access %ld bytes of target "
"memory at 0x%lx, halting search.",
(long) search_buf_size, (long) start_addr);
return -1;
}
/* Perform the search.
The loop is kept simple by allocating [N + pattern-length - 1] bytes.
When we've scanned N bytes we copy the trailing bytes to the start and
read in another N bytes. */