forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.cc
5125 lines (4293 loc) · 129 KB
/
server.cc
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-2024 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 "gdbthread.h"
#include "gdbsupport/agent.h"
#include "notif.h"
#include "tdesc.h"
#include "gdbsupport/rsp-low.h"
#include "gdbsupport/signals-state-save-restore.h"
#include <ctype.h>
#include <unistd.h>
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#include "gdbsupport/gdb_vecs.h"
#include "gdbsupport/gdb_wait.h"
#include "gdbsupport/btrace-common.h"
#include "gdbsupport/filestuff.h"
#include "tracepoint.h"
#include "dll.h"
#include "hostio.h"
#include <vector>
#include "gdbsupport/unordered_map.h"
#include "gdbsupport/common-inferior.h"
#include "gdbsupport/job-control.h"
#include "gdbsupport/environ.h"
#include "filenames.h"
#include "gdbsupport/pathstuff.h"
#ifdef USE_XML
#include "xml-builtin.h"
#endif
#include "gdbsupport/selftest.h"
#include "gdbsupport/scope-exit.h"
#include "gdbsupport/gdb_select.h"
#include "gdbsupport/scoped_restore.h"
#include "gdbsupport/search.h"
#include "gdbsupport/gdb_argv_vec.h"
/* PBUFSIZ must also be at least as big as IPA_CMD_BUF_SIZE, because
the client state data is passed directly to some agent
functions. */
static_assert (PBUFSIZ >= IPA_CMD_BUF_SIZE);
#define require_running_or_return(BUF) \
if (!target_running ()) \
{ \
write_enn (BUF); \
return; \
}
#define require_running_or_break(BUF) \
if (!target_running ()) \
{ \
write_enn (BUF); \
break; \
}
/* The environment to pass to the inferior when creating it. */
static gdb_environ our_environ;
bool server_waiting;
static bool extended_protocol;
static bool response_needed;
static bool exit_requested;
/* --once: Exit after the first connection has closed. */
bool run_once;
/* Whether to report TARGET_WAITKIND_NO_RESUMED events. */
static bool report_no_resumed;
/* The event loop checks this to decide whether to continue accepting
events. */
static bool keep_processing_events = true;
bool non_stop;
static struct {
/* Set the PROGRAM_PATH. Here we adjust the path of the provided
binary if needed. */
void set (const char *path)
{
m_path = path;
/* Make sure we're using the absolute path of the inferior when
creating it. */
if (!contains_dir_separator (m_path.c_str ()))
{
int reg_file_errno;
/* Check if the file is in our CWD. If it is, then we prefix
its name with CURRENT_DIRECTORY. Otherwise, we leave the
name as-is because we'll try searching for it in $PATH. */
if (is_regular_file (m_path.c_str (), ®_file_errno))
m_path = gdb_abspath (m_path);
}
}
/* Return the PROGRAM_PATH. */
const char *get ()
{ return m_path.empty () ? nullptr : m_path.c_str (); }
private:
/* The program name, adjusted if needed. */
std::string m_path;
} program_path;
/* All program arguments are merged into a single string. */
static std::string program_args;
static std::string wrapper_argv;
/* 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;
/* 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. */
bool disable_packet_vCont;
bool disable_packet_Tthread;
bool disable_packet_qC;
bool disable_packet_qfThreadInfo;
bool disable_packet_T;
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 : public notif_event
{
/* 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;
/* The client remote protocol state. */
static client_state g_client_state;
client_state &
get_client_state ()
{
client_state &cs = g_client_state;
return cs;
}
/* Put a stop reply to the stop reply queue. */
static void
queue_stop_reply (ptid_t ptid, const target_waitstatus &status)
{
struct vstop_notif *new_notif = new struct vstop_notif;
new_notif->ptid = ptid;
new_notif->status = status;
notif_event_enque (¬if_stop, new_notif);
}
static bool
remove_all_on_match_ptid (struct notif_event *event, ptid_t filter_ptid)
{
struct vstop_notif *vstop_event = (struct vstop_notif *) event;
return vstop_event->ptid.matches (filter_ptid);
}
/* See server.h. */
void
discard_queued_stop_replies (ptid_t ptid)
{
std::list<notif_event *>::iterator iter, next, end;
end = notif_stop.queue.end ();
for (iter = notif_stop.queue.begin (); iter != end; iter = next)
{
next = iter;
++next;
if (iter == notif_stop.queue.begin ())
{
/* The head of the list contains the notification that was
already sent to GDB. So we can't remove it, otherwise
when GDB sends the vStopped, it would ack the _next_
notification, which hadn't been sent yet! */
continue;
}
if (remove_all_on_match_ptid (*iter, ptid))
{
delete *iter;
notif_stop.queue.erase (iter);
}
}
}
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);
}
/* Helper for in_queued_stop_replies. */
static bool
in_queued_stop_replies_ptid (struct notif_event *event, ptid_t filter_ptid)
{
struct vstop_notif *vstop_event = (struct vstop_notif *) event;
if (vstop_event->ptid.matches (filter_ptid))
return true;
/* 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
|| vstop_event->status.kind () == TARGET_WAITKIND_THREAD_CLONED)
&& vstop_event->status.child_ptid ().matches (filter_ptid))
return true;
return false;
}
/* See server.h. */
int
in_queued_stop_replies (ptid_t ptid)
{
for (notif_event *event : notif_stop.queue)
{
if (in_queued_stop_replies_ptid (event, ptid))
return true;
}
return false;
}
struct notif_server notif_stop =
{
"vStopped", "Stop", {}, vstop_notif_reply,
};
static int
target_running (void)
{
return get_first_thread () != NULL;
}
/* See gdbsupport/common-inferior.h. */
const char *
get_exec_wrapper ()
{
return !wrapper_argv.empty () ? wrapper_argv.c_str () : NULL;
}
/* See server.h. */
gdb_environ *
get_environ ()
{
return &our_environ;
}
static int
attach_inferior (int pid)
{
client_state &cs = get_client_state ();
/* myattach should return -1 if attaching is unsupported,
0 if it succeeded, and call error() otherwise. */
if (find_process_pid (pid) != nullptr)
error ("Already attached to process %d\n", pid);
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)
{
cs.last_ptid = mywait (ptid_t (pid), &cs.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 (cs.last_status.kind () == TARGET_WAITKIND_STOPPED
&& cs.last_status.sig () == GDB_SIGNAL_STOP)
cs.last_status.set_stopped (GDB_SIGNAL_TRAP);
current_thread->last_resume_kind = resume_stop;
current_thread->last_status = cs.last_status;
}
return 0;
}
/* 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 void
handle_btrace_enable_bts (thread_info *thread)
{
if (thread->btrace != NULL)
error (_("Btrace already enabled."));
current_btrace_conf.format = BTRACE_FORMAT_BTS;
thread->btrace = target_enable_btrace (thread, ¤t_btrace_conf);
}
/* Handle btrace enabling in Intel Processor Trace format. */
static void
handle_btrace_enable_pt (thread_info *thread)
{
if (thread->btrace != NULL)
error (_("Btrace already enabled."));
current_btrace_conf.format = BTRACE_FORMAT_PT;
thread->btrace = target_enable_btrace (thread, ¤t_btrace_conf);
}
/* Handle btrace disabling. */
static void
handle_btrace_disable (thread_info *thread)
{
if (thread->btrace == NULL)
error (_("Branch tracing not enabled."));
if (target_disable_btrace (thread->btrace) != 0)
error (_("Could not disable branch tracing."));
thread->btrace = NULL;
}
/* Handle the "Qbtrace" packet. */
static int
handle_btrace_general_set (char *own_buf)
{
client_state &cs = get_client_state ();
thread_info *thread;
char *op;
if (!startswith (own_buf, "Qbtrace:"))
return 0;
op = own_buf + strlen ("Qbtrace:");
if (cs.general_thread == null_ptid
|| cs.general_thread == minus_one_ptid)
{
strcpy (own_buf, "E.Must select a single thread.");
return -1;
}
thread = find_thread_ptid (cs.general_thread);
if (thread == NULL)
{
strcpy (own_buf, "E.No such thread.");
return -1;
}
try
{
if (strcmp (op, "bts") == 0)
handle_btrace_enable_bts (thread);
else if (strcmp (op, "pt") == 0)
handle_btrace_enable_pt (thread);
else if (strcmp (op, "off") == 0)
handle_btrace_disable (thread);
else
error (_("Bad Qbtrace operation. Use bts, pt, or off."));
write_ok (own_buf);
}
catch (const gdb_exception_error &exception)
{
sprintf (own_buf, "E.%s", exception.what ());
}
return 1;
}
/* Handle the "Qbtrace-conf" packet. */
static int
handle_btrace_conf_general_set (char *own_buf)
{
client_state &cs = get_client_state ();
thread_info *thread;
char *op;
if (!startswith (own_buf, "Qbtrace-conf:"))
return 0;
op = own_buf + strlen ("Qbtrace-conf:");
if (cs.general_thread == null_ptid
|| cs.general_thread == minus_one_ptid)
{
strcpy (own_buf, "E.Must select a single thread.");
return -1;
}
thread = find_thread_ptid (cs.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 if (strncmp (op, "pt:ptwrite=", strlen ("pt:ptwrite=")) == 0)
{
op += strlen ("pt:ptwrite=");
if (strncmp (op, "\"yes\"", strlen ("\"yes\"")) == 0)
current_btrace_conf.pt.ptwrite = true;
else if (strncmp (op, "\"no\"", strlen ("\"no\"")) == 0)
current_btrace_conf.pt.ptwrite = false;
else
{
strcpy (own_buf, "E.Bad ptwrite value.");
return -1;
}
}
else if (strncmp (op, "pt:event-tracing=", strlen ("pt:event-tracing=")) == 0)
{
op += strlen ("pt:event-tracing=");
if (strncmp (op, "\"yes\"", strlen ("\"yes\"")) == 0)
current_btrace_conf.pt.event_tracing = true;
else if (strncmp (op, "\"no\"", strlen ("\"no\"")) == 0)
current_btrace_conf.pt.event_tracing = false;
else
{
strcpy (own_buf, "E.Bad event-tracing value.");
return -1;
}
}
else
{
strcpy (own_buf, "E.Bad Qbtrace configuration option.");
return -1;
}
write_ok (own_buf);
return 1;
}
/* Create the qMemTags packet reply given TAGS.
Returns true if parsing succeeded and false otherwise. */
static bool
create_fetch_memtags_reply (char *reply, const gdb::byte_vector &tags)
{
/* It is an error to pass a zero-sized tag vector. */
gdb_assert (tags.size () != 0);
std::string packet ("m");
/* Write the tag data. */
packet += bin2hex (tags.data (), tags.size ());
/* Check if the reply is too big for the packet to handle. */
if (PBUFSIZ < packet.size ())
return false;
strcpy (reply, packet.c_str ());
return true;
}
/* Parse the QMemTags request into ADDR, LEN and TAGS.
Returns true if parsing succeeded and false otherwise. */
static bool
parse_store_memtags_request (char *request, CORE_ADDR *addr, size_t *len,
gdb::byte_vector &tags, int *type)
{
gdb_assert (startswith (request, "QMemTags:"));
const char *p = request + strlen ("QMemTags:");
/* Read address and length. */
unsigned int length = 0;
p = decode_m_packet_params (p, addr, &length, ':');
*len = length;
/* Read the tag type. */
ULONGEST tag_type = 0;
p = unpack_varlen_hex (p, &tag_type);
*type = (int) tag_type;
/* Make sure there is a colon after the type. */
if (*p != ':')
return false;
/* Skip the colon. */
p++;
/* Read the tag data. */
tags = hex2bin (p);
return true;
}
/* Parse thread options starting at *P and return them. On exit,
advance *P past the options. */
static gdb_thread_options
parse_gdb_thread_options (const char **p)
{
ULONGEST options = 0;
*p = unpack_varlen_hex (*p, &options);
return (gdb_thread_option) options;
}
/* Handle all of the extended 'Q' packets. */
static void
handle_general_set (char *own_buf)
{
client_state &cs = get_client_state ();
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)
{
cs.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
cs.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;
cs.program_signals_p = 1;
p = decode_address_to_semicolon (&cursig, p);
for (i = 0; i < numsigs; i++)
{
if (i == cursig)
{
cs.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
cs.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 ();
process->syscalls_to_catch.clear ();
if (enabled)
{
p += 1;
if (*p == ';')
{
p += 1;
while (*p != '\0')
{
p = decode_address_to_semicolon (&sysno, p);
process->syscalls_to_catch.push_back (sysno);
}
}
else
process->syscalls_to_catch.push_back (ANY_SYSCALL);
}
write_ok (own_buf);
return;
}
if (strcmp (own_buf, "QEnvironmentReset") == 0)
{
our_environ = gdb_environ::from_host_environ ();
write_ok (own_buf);
return;
}
if (startswith (own_buf, "QEnvironmentHexEncoded:"))
{
const char *p = own_buf + sizeof ("QEnvironmentHexEncoded:") - 1;
/* The final form of the environment variable. FINAL_VAR will
hold the 'VAR=VALUE' format. */
std::string final_var = hex2str (p);
std::string var_name, var_value;
remote_debug_printf ("[QEnvironmentHexEncoded received '%s']", p);
remote_debug_printf ("[Environment variable to be set: '%s']",
final_var.c_str ());
size_t pos = final_var.find ('=');
if (pos == std::string::npos)
{
warning (_("Unexpected format for environment variable: '%s'"),
final_var.c_str ());
write_enn (own_buf);
return;
}
var_name = final_var.substr (0, pos);
var_value = final_var.substr (pos + 1, std::string::npos);
our_environ.set (var_name.c_str (), var_value.c_str ());
write_ok (own_buf);
return;
}
if (startswith (own_buf, "QEnvironmentUnset:"))
{
const char *p = own_buf + sizeof ("QEnvironmentUnset:") - 1;
std::string varname = hex2str (p);
remote_debug_printf ("[QEnvironmentUnset received '%s']", p);
remote_debug_printf ("[Environment variable to be unset: '%s']",
varname.c_str ());
our_environ.unset (varname.c_str ());
write_ok (own_buf);
return;
}
if (strcmp (own_buf, "QStartNoAckMode") == 0)
{
remote_debug_printf ("[noack mode enabled]");
cs.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 (the_target->start_non_stop (req == 1) != 0)
{
fprintf (stderr, "Setting %s mode failed\n", req_str);
write_enn (own_buf);
return;
}
non_stop = (req != 0);
remote_debug_printf ("[%s mode enabled]", 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);
cs.disable_randomization = setting;
remote_debug_printf (cs.disable_randomization
? "[address space randomization disabled]"
: "[address space randomization enabled]");
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;
remote_debug_printf ("[%s agent]", 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
{
/* We don't know what this mode is, so complain to GDB. */
std::string err
= string_printf ("E.Unknown thread-events mode requested: %s\n",
mode);
strcpy (own_buf, err.c_str ());
return;
}
cs.report_thread_events = (req == TRIBOOL_TRUE);
remote_debug_printf ("[thread events are now %s]\n",
cs.report_thread_events ? "enabled" : "disabled");
write_ok (own_buf);
return;
}
if (startswith (own_buf, "QThreadOptions;"))
{
const char *p = own_buf + strlen ("QThreadOptions");
gdb_thread_options supported_options = target_supported_thread_options ();
if (supported_options == 0)
{
/* Something went wrong -- we don't support any option, but
GDB sent the packet anyway. */
write_enn (own_buf);
return;
}
/* We could store the options directly in thread->thread_options
without this map, but that would mean that a QThreadOptions
packet with a wildcard like "QThreadOptions;0;3:TID" would
result in the debug logs showing:
[options for TID are now 0x0]
[options for TID are now 0x3]
It's nicer if we only print the final options for each TID,
and if we only print about it if the options changed compared
to the options that were previously set on the thread. */
gdb::unordered_map<thread_info *, gdb_thread_options> set_options;
while (*p != '\0')
{
if (p[0] != ';')
{
write_enn (own_buf);
return;
}
p++;
/* Read the options. */
gdb_thread_options options = parse_gdb_thread_options (&p);
if ((options & ~supported_options) != 0)
{
/* GDB asked for an unknown or unsupported option, so
error out. */
std::string err
= string_printf ("E.Unknown thread options requested: %s\n",
to_string (options).c_str ());
strcpy (own_buf, err.c_str ());
return;
}
ptid_t ptid;
if (p[0] == ';' || p[0] == '\0')
ptid = minus_one_ptid;
else if (p[0] == ':')
{
const char *q;
ptid = read_ptid (p + 1, &q);
if (p == q)
{
write_enn (own_buf);
return;
}
p = q;
if (p[0] != ';' && p[0] != '\0')
{
write_enn (own_buf);
return;