forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget.c
4619 lines (3722 loc) · 117 KB
/
target.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
/* Select target systems and architectures at runtime for GDB.
Copyright (C) 1990-2024 Free Software Foundation, Inc.
Contributed by Cygnus Support.
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 "target.h"
#include "extract-store-integer.h"
#include "target-dcache.h"
#include "cli/cli-cmds.h"
#include "symtab.h"
#include "inferior.h"
#include "infrun.h"
#include "observable.h"
#include "bfd.h"
#include "symfile.h"
#include "objfiles.h"
#include "dcache.h"
#include <signal.h>
#include "regcache.h"
#include "gdbcore.h"
#include "target-descriptions.h"
#include "gdbthread.h"
#include "solib.h"
#include "exec.h"
#include "inline-frame.h"
#include "tracepoint.h"
#include "gdbsupport/fileio.h"
#include "gdbsupport/agent.h"
#include "auxv.h"
#include "target-debug.h"
#include "ui.h"
#include "event-top.h"
#include <algorithm>
#include "gdbsupport/byte-vector.h"
#include "gdbsupport/search.h"
#include "terminal.h"
#include "gdbsupport/unordered_map.h"
#include "target-connection.h"
#include "valprint.h"
#include "cli/cli-decode.h"
#include "cli/cli-style.h"
[[noreturn]] static void generic_tls_error (void);
static void default_rcmd (struct target_ops *, const char *, struct ui_file *);
static int default_verify_memory (struct target_ops *self,
const gdb_byte *data,
CORE_ADDR memaddr, ULONGEST size);
[[noreturn]] static void tcomplain (void);
/* Mapping between target_info objects (which have address identity)
and corresponding open/factory function/callback. Each add_target
call adds one entry to this map, and registers a "target
TARGET_NAME" command that when invoked calls the factory registered
here. The target_info object is associated with the command via
the command's context. */
static gdb::unordered_map<const target_info *, target_open_ftype *>
target_factories;
/* The singleton debug target. */
static struct target_ops *the_debug_target;
/* Command list for target. */
static struct cmd_list_element *targetlist = NULL;
/* See target.h. */
bool trust_readonly = false;
/* Nonzero if we should show true memory content including
memory breakpoint inserted by gdb. */
static int show_memory_breakpoints = 0;
/* These globals control whether GDB attempts to perform these
operations; they are useful for targets that need to prevent
inadvertent disruption, such as in non-stop mode. */
bool may_write_registers = true;
bool may_write_memory = true;
bool may_insert_breakpoints = true;
bool may_insert_tracepoints = true;
bool may_insert_fast_tracepoints = true;
bool may_stop = true;
/* Non-zero if we want to see trace of target level stuff. */
static unsigned int targetdebug = 0;
/* Print a "target" debug statement with the function name prefix. */
#define target_debug_printf(fmt, ...) \
debug_prefixed_printf_cond (targetdebug > 0, "target", fmt, ##__VA_ARGS__)
/* Print a "target" debug statement without the function name prefix. */
#define target_debug_printf_nofunc(fmt, ...) \
debug_prefixed_printf_cond_nofunc (targetdebug > 0, "target", fmt, ##__VA_ARGS__)
static void
set_targetdebug (const char *args, int from_tty, struct cmd_list_element *c)
{
if (targetdebug)
current_inferior ()->push_target (the_debug_target);
else
current_inferior ()->unpush_target (the_debug_target);
}
static void
show_targetdebug (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
gdb_printf (file, _("Target debugging is %s.\n"), value);
}
int
target_has_memory ()
{
for (target_ops *t = current_inferior ()->top_target ();
t != NULL;
t = t->beneath ())
if (t->has_memory ())
return 1;
return 0;
}
int
target_has_stack ()
{
for (target_ops *t = current_inferior ()->top_target ();
t != NULL;
t = t->beneath ())
if (t->has_stack ())
return 1;
return 0;
}
int
target_has_registers ()
{
for (target_ops *t = current_inferior ()->top_target ();
t != NULL;
t = t->beneath ())
if (t->has_registers ())
return 1;
return 0;
}
bool
target_has_execution (inferior *inf)
{
if (inf == nullptr)
inf = current_inferior ();
for (target_ops *t = inf->top_target ();
t != nullptr;
t = inf->find_target_beneath (t))
if (t->has_execution (inf))
return true;
return false;
}
const char *
target_shortname ()
{
return current_inferior ()->top_target ()->shortname ();
}
/* See target.h. */
bool
target_attach_no_wait ()
{
return current_inferior ()->top_target ()->attach_no_wait ();
}
/* See target.h. */
void
target_post_attach (int pid)
{
return current_inferior ()->top_target ()->post_attach (pid);
}
/* See target.h. */
void
target_prepare_to_store (regcache *regcache)
{
return current_inferior ()->top_target ()->prepare_to_store (regcache);
}
/* See target.h. */
bool
target_supports_enable_disable_tracepoint ()
{
target_ops *target = current_inferior ()->top_target ();
return target->supports_enable_disable_tracepoint ();
}
bool
target_supports_string_tracing ()
{
return current_inferior ()->top_target ()->supports_string_tracing ();
}
/* See target.h. */
bool
target_supports_evaluation_of_breakpoint_conditions ()
{
target_ops *target = current_inferior ()->top_target ();
return target->supports_evaluation_of_breakpoint_conditions ();
}
/* See target.h. */
bool
target_supports_dumpcore ()
{
return current_inferior ()->top_target ()->supports_dumpcore ();
}
/* See target.h. */
void
target_dumpcore (const char *filename)
{
return current_inferior ()->top_target ()->dumpcore (filename);
}
/* See target.h. */
bool
target_can_run_breakpoint_commands ()
{
return current_inferior ()->top_target ()->can_run_breakpoint_commands ();
}
/* See target.h. */
void
target_files_info ()
{
return current_inferior ()->top_target ()->files_info ();
}
/* See target.h. */
int
target_insert_fork_catchpoint (int pid)
{
return current_inferior ()->top_target ()->insert_fork_catchpoint (pid);
}
/* See target.h. */
int
target_remove_fork_catchpoint (int pid)
{
return current_inferior ()->top_target ()->remove_fork_catchpoint (pid);
}
/* See target.h. */
int
target_insert_vfork_catchpoint (int pid)
{
return current_inferior ()->top_target ()->insert_vfork_catchpoint (pid);
}
/* See target.h. */
int
target_remove_vfork_catchpoint (int pid)
{
return current_inferior ()->top_target ()->remove_vfork_catchpoint (pid);
}
/* See target.h. */
int
target_insert_exec_catchpoint (int pid)
{
return current_inferior ()->top_target ()->insert_exec_catchpoint (pid);
}
/* See target.h. */
int
target_remove_exec_catchpoint (int pid)
{
return current_inferior ()->top_target ()->remove_exec_catchpoint (pid);
}
/* See target.h. */
int
target_set_syscall_catchpoint (int pid, bool needed, int any_count,
gdb::array_view<const int> syscall_counts)
{
target_ops *target = current_inferior ()->top_target ();
return target->set_syscall_catchpoint (pid, needed, any_count,
syscall_counts);
}
/* See target.h. */
void
target_rcmd (const char *command, struct ui_file *outbuf)
{
return current_inferior ()->top_target ()->rcmd (command, outbuf);
}
/* See target.h. */
bool
target_can_lock_scheduler ()
{
target_ops *target = current_inferior ()->top_target ();
return (target->get_thread_control_capabilities ()& tc_schedlock) != 0;
}
/* See target.h. */
bool
target_can_async_p ()
{
return target_can_async_p (current_inferior ()->top_target ());
}
/* See target.h. */
bool
target_can_async_p (struct target_ops *target)
{
if (!target_async_permitted)
return false;
return target->can_async_p ();
}
/* See target.h. */
bool
target_is_async_p ()
{
bool result = current_inferior ()->top_target ()->is_async_p ();
gdb_assert (target_async_permitted || !result);
return result;
}
exec_direction_kind
target_execution_direction ()
{
return current_inferior ()->top_target ()->execution_direction ();
}
/* See target.h. */
const char *
target_extra_thread_info (thread_info *tp)
{
return current_inferior ()->top_target ()->extra_thread_info (tp);
}
/* See target.h. */
const char *
target_pid_to_exec_file (int pid)
{
return current_inferior ()->top_target ()->pid_to_exec_file (pid);
}
/* See target.h. */
gdbarch *
target_thread_architecture (ptid_t ptid)
{
return current_inferior ()->top_target ()->thread_architecture (ptid);
}
/* See target.h. */
int
target_find_memory_regions (find_memory_region_ftype func, void *data)
{
return current_inferior ()->top_target ()->find_memory_regions (func, data);
}
/* See target.h. */
gdb::unique_xmalloc_ptr<char>
target_make_corefile_notes (bfd *bfd, int *size_p)
{
return current_inferior ()->top_target ()->make_corefile_notes (bfd, size_p);
}
gdb_byte *
target_get_bookmark (const char *args, int from_tty)
{
return current_inferior ()->top_target ()->get_bookmark (args, from_tty);
}
void
target_goto_bookmark (const gdb_byte *arg, int from_tty)
{
return current_inferior ()->top_target ()->goto_bookmark (arg, from_tty);
}
/* See target.h. */
bool
target_stopped_by_watchpoint ()
{
return current_inferior ()->top_target ()->stopped_by_watchpoint ();
}
/* See target.h. */
bool
target_stopped_by_sw_breakpoint ()
{
return current_inferior ()->top_target ()->stopped_by_sw_breakpoint ();
}
bool
target_supports_stopped_by_sw_breakpoint ()
{
target_ops *target = current_inferior ()->top_target ();
return target->supports_stopped_by_sw_breakpoint ();
}
bool
target_stopped_by_hw_breakpoint ()
{
return current_inferior ()->top_target ()->stopped_by_hw_breakpoint ();
}
bool
target_supports_stopped_by_hw_breakpoint ()
{
target_ops *target = current_inferior ()->top_target ();
return target->supports_stopped_by_hw_breakpoint ();
}
/* See target.h. */
bool
target_have_steppable_watchpoint ()
{
return current_inferior ()->top_target ()->have_steppable_watchpoint ();
}
/* See target.h. */
int
target_can_use_hardware_watchpoint (bptype type, int cnt, int othertype)
{
target_ops *target = current_inferior ()->top_target ();
return target->can_use_hw_breakpoint (type, cnt, othertype);
}
/* See target.h. */
int
target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
{
target_ops *target = current_inferior ()->top_target ();
return target->region_ok_for_hw_watchpoint (addr, len);
}
int
target_can_do_single_step ()
{
return current_inferior ()->top_target ()->can_do_single_step ();
}
/* See target.h. */
int
target_insert_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
expression *cond)
{
target_ops *target = current_inferior ()->top_target ();
return target->insert_watchpoint (addr, len, type, cond);
}
/* See target.h. */
int
target_remove_watchpoint (CORE_ADDR addr, int len, target_hw_bp_type type,
expression *cond)
{
target_ops *target = current_inferior ()->top_target ();
return target->remove_watchpoint (addr, len, type, cond);
}
/* See target.h. */
int
target_insert_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
{
target_ops *target = current_inferior ()->top_target ();
return target->insert_hw_breakpoint (gdbarch, bp_tgt);
}
/* See target.h. */
int
target_remove_hw_breakpoint (gdbarch *gdbarch, bp_target_info *bp_tgt)
{
target_ops *target = current_inferior ()->top_target ();
return target->remove_hw_breakpoint (gdbarch, bp_tgt);
}
/* See target.h. */
bool
target_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int type,
expression *cond)
{
target_ops *target = current_inferior ()->top_target ();
return target->can_accel_watchpoint_condition (addr, len, type, cond);
}
/* See target.h. */
bool
target_can_execute_reverse ()
{
return current_inferior ()->top_target ()->can_execute_reverse ();
}
ptid_t
target_get_ada_task_ptid (long lwp, ULONGEST tid)
{
return current_inferior ()->top_target ()->get_ada_task_ptid (lwp, tid);
}
bool
target_filesystem_is_local ()
{
return current_inferior ()->top_target ()->filesystem_is_local ();
}
void
target_trace_init ()
{
return current_inferior ()->top_target ()->trace_init ();
}
void
target_download_tracepoint (bp_location *location)
{
return current_inferior ()->top_target ()->download_tracepoint (location);
}
bool
target_can_download_tracepoint ()
{
return current_inferior ()->top_target ()->can_download_tracepoint ();
}
void
target_download_trace_state_variable (const trace_state_variable &tsv)
{
target_ops *target = current_inferior ()->top_target ();
return target->download_trace_state_variable (tsv);
}
void
target_enable_tracepoint (bp_location *loc)
{
return current_inferior ()->top_target ()->enable_tracepoint (loc);
}
void
target_disable_tracepoint (bp_location *loc)
{
return current_inferior ()->top_target ()->disable_tracepoint (loc);
}
void
target_trace_start ()
{
return current_inferior ()->top_target ()->trace_start ();
}
void
target_trace_set_readonly_regions ()
{
return current_inferior ()->top_target ()->trace_set_readonly_regions ();
}
int
target_get_trace_status (trace_status *ts)
{
return current_inferior ()->top_target ()->get_trace_status (ts);
}
void
target_get_tracepoint_status (tracepoint *tp, uploaded_tp *utp)
{
return current_inferior ()->top_target ()->get_tracepoint_status (tp, utp);
}
void
target_trace_stop ()
{
return current_inferior ()->top_target ()->trace_stop ();
}
int
target_trace_find (trace_find_type type, int num,
CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
{
target_ops *target = current_inferior ()->top_target ();
return target->trace_find (type, num, addr1, addr2, tpp);
}
bool
target_get_trace_state_variable_value (int tsv, LONGEST *val)
{
target_ops *target = current_inferior ()->top_target ();
return target->get_trace_state_variable_value (tsv, val);
}
int
target_save_trace_data (const char *filename)
{
return current_inferior ()->top_target ()->save_trace_data (filename);
}
int
target_upload_tracepoints (uploaded_tp **utpp)
{
return current_inferior ()->top_target ()->upload_tracepoints (utpp);
}
int
target_upload_trace_state_variables (uploaded_tsv **utsvp)
{
target_ops *target = current_inferior ()->top_target ();
return target->upload_trace_state_variables (utsvp);
}
LONGEST
target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset, LONGEST len)
{
target_ops *target = current_inferior ()->top_target ();
return target->get_raw_trace_data (buf, offset, len);
}
int
target_get_min_fast_tracepoint_insn_len ()
{
target_ops *target = current_inferior ()->top_target ();
return target->get_min_fast_tracepoint_insn_len ();
}
void
target_set_disconnected_tracing (int val)
{
return current_inferior ()->top_target ()->set_disconnected_tracing (val);
}
void
target_set_circular_trace_buffer (int val)
{
return current_inferior ()->top_target ()->set_circular_trace_buffer (val);
}
void
target_set_trace_buffer_size (LONGEST val)
{
return current_inferior ()->top_target ()->set_trace_buffer_size (val);
}
bool
target_set_trace_notes (const char *user, const char *notes,
const char *stopnotes)
{
target_ops *target = current_inferior ()->top_target ();
return target->set_trace_notes (user, notes, stopnotes);
}
bool
target_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
{
return current_inferior ()->top_target ()->get_tib_address (ptid, addr);
}
void
target_set_permissions ()
{
return current_inferior ()->top_target ()->set_permissions ();
}
bool
target_static_tracepoint_marker_at (CORE_ADDR addr,
static_tracepoint_marker *marker)
{
target_ops *target = current_inferior ()->top_target ();
return target->static_tracepoint_marker_at (addr, marker);
}
std::vector<static_tracepoint_marker>
target_static_tracepoint_markers_by_strid (const char *marker_id)
{
target_ops *target = current_inferior ()->top_target ();
return target->static_tracepoint_markers_by_strid (marker_id);
}
traceframe_info_up
target_traceframe_info ()
{
return current_inferior ()->top_target ()->traceframe_info ();
}
bool
target_use_agent (bool use)
{
return current_inferior ()->top_target ()->use_agent (use);
}
bool
target_can_use_agent ()
{
return current_inferior ()->top_target ()->can_use_agent ();
}
bool
target_augmented_libraries_svr4_read ()
{
return current_inferior ()->top_target ()->augmented_libraries_svr4_read ();
}
bool
target_supports_memory_tagging ()
{
return current_inferior ()->top_target ()->supports_memory_tagging ();
}
bool
target_fetch_memtags (CORE_ADDR address, size_t len, gdb::byte_vector &tags,
int type)
{
return current_inferior ()->top_target ()->fetch_memtags (address, len, tags, type);
}
bool
target_store_memtags (CORE_ADDR address, size_t len,
const gdb::byte_vector &tags, int type)
{
return current_inferior ()->top_target ()->store_memtags (address, len, tags, type);
}
bool
target_is_address_tagged (gdbarch *gdbarch, CORE_ADDR address)
{
return current_inferior ()->top_target ()->is_address_tagged (gdbarch, address);
}
x86_xsave_layout
target_fetch_x86_xsave_layout ()
{
return current_inferior ()->top_target ()->fetch_x86_xsave_layout ();
}
void
target_log_command (const char *p)
{
return current_inferior ()->top_target ()->log_command (p);
}
/* This is used to implement the various target commands. */
static void
open_target (const char *args, int from_tty, struct cmd_list_element *command)
{
auto *ti = static_cast<target_info *> (command->context ());
target_open_ftype *func = target_factories[ti];
target_debug_printf_nofunc ("-> %s->open (...)", ti->shortname);
func (args, from_tty);
target_debug_printf_nofunc ("<- %s->open (%s, %d)", ti->shortname, args, from_tty);
}
/* See target.h. */
void
add_target (const target_info &t, target_open_ftype *func,
completer_ftype *completer)
{
struct cmd_list_element *c;
auto &func_slot = target_factories[&t];
if (func_slot != nullptr)
internal_error (_("target already added (\"%s\")."), t.shortname);
func_slot = func;
if (targetlist == NULL)
add_basic_prefix_cmd ("target", class_run, _("\
Connect to a target machine or process.\n\
The first argument is the type or protocol of the target machine.\n\
Remaining arguments are interpreted by the target protocol. For more\n\
information on the arguments for a particular protocol, type\n\
`help target ' followed by the protocol name."),
&targetlist, 0, &cmdlist);
c = add_cmd (t.shortname, no_class, t.doc, &targetlist);
c->set_context ((void *) &t);
c->func = open_target;
if (completer != NULL)
set_cmd_completer (c, completer);
}
/* See target.h. */
void
add_deprecated_target_alias (const target_info &tinfo, const char *alias)
{
struct cmd_list_element *c;
/* If we use add_alias_cmd, here, we do not get the deprecated warning,
see PR cli/15104. */
c = add_cmd (alias, no_class, tinfo.doc, &targetlist);
c->func = open_target;
c->set_context ((void *) &tinfo);
gdb::unique_xmalloc_ptr<char> alt
= xstrprintf ("target %s", tinfo.shortname);
deprecate_cmd (c, alt.release ());
}
/* Stub functions */
void
target_kill (void)
{
/* If the commit_resume_state of the to-be-killed-inferior's process stratum
is true, and this inferior is the last live inferior with resumed threads
of that target, then we want to leave commit_resume_state to false, as the
target won't have any resumed threads anymore. We achieve this with
this scoped_disable_commit_resumed. On construction, it will set the flag
to false. On destruction, it will only set it to true if there are resumed
threads left. */
scoped_disable_commit_resumed disable ("killing");
current_inferior ()->top_target ()->kill ();
}
void
target_load (const char *arg, int from_tty)
{
target_dcache_invalidate (current_program_space->aspace);
current_inferior ()->top_target ()->load (arg, from_tty);
}
/* Define it. */
target_terminal_state target_terminal::m_terminal_state
= target_terminal_state::is_ours;
/* See target/target.h. */
void
target_terminal::init (void)
{
current_inferior ()->top_target ()->terminal_init ();
m_terminal_state = target_terminal_state::is_ours;
}
/* See target/target.h. */
void
target_terminal::inferior (void)
{
struct ui *ui = current_ui;
/* A background resume (``run&'') should leave GDB in control of the
terminal. */
if (ui->prompt_state != PROMPT_BLOCKED)
return;
/* Since we always run the inferior in the main console (unless "set
inferior-tty" is in effect), when some UI other than the main one
calls target_terminal::inferior, then we leave the main UI's
terminal settings as is. */
if (ui != main_ui)
return;
/* If GDB is resuming the inferior in the foreground, install
inferior's terminal modes. */
struct inferior *inf = current_inferior ();
if (inf->terminal_state != target_terminal_state::is_inferior)
{
current_inferior ()->top_target ()->terminal_inferior ();
inf->terminal_state = target_terminal_state::is_inferior;
}
m_terminal_state = target_terminal_state::is_inferior;
/* If the user hit C-c before, pretend that it was hit right
here. */
if (check_quit_flag ())
target_pass_ctrlc ();
}
/* See target/target.h. */
void
target_terminal::restore_inferior (void)
{
struct ui *ui = current_ui;
/* See target_terminal::inferior(). */
if (ui->prompt_state != PROMPT_BLOCKED || ui != main_ui)
return;
/* Restore the terminal settings of inferiors that were in the
foreground but are now ours_for_output due to a temporary
target_target::ours_for_output() call. */
{
scoped_restore_current_inferior restore_inferior;
for (::inferior *inf : all_inferiors ())
{
if (inf->terminal_state == target_terminal_state::is_ours_for_output)
{
set_current_inferior (inf);
current_inferior ()->top_target ()->terminal_inferior ();
inf->terminal_state = target_terminal_state::is_inferior;
}
}
}
m_terminal_state = target_terminal_state::is_inferior;
/* If the user hit C-c before, pretend that it was hit right
here. */
if (check_quit_flag ())
target_pass_ctrlc ();
}