GDB (xrefs)
Loading...
Searching...
No Matches
scm-arch.c
Go to the documentation of this file.
1/* Scheme interface to architecture.
2
3 Copyright (C) 2014-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20/* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
22
23#include "defs.h"
24#include "charset.h"
25#include "gdbarch.h"
26#include "arch-utils.h"
27#include "guile-internal.h"
28
29/* The <gdb:arch> smob. */
30
32{
33 /* This always appears first. */
35
37};
38
39static const char arch_smob_name[] = "gdb:arch";
40
41/* The tag Guile knows the arch smob by. */
42static scm_t_bits arch_smob_tag;
43
44/* Use a 'void *' here because it isn't guaranteed that SCM is a
45 pointer. */
46static const registry<gdbarch>::key<void, gdb::noop_deleter<void>>
48
49static int arscm_is_arch (SCM);
50
51/* Administrivia for arch smobs. */
52
53/* The smob "print" function for <gdb:arch>. */
54
55static int
56arscm_print_arch_smob (SCM self, SCM port, scm_print_state *pstate)
57{
58 arch_smob *a_smob = (arch_smob *) SCM_SMOB_DATA (self);
59 struct gdbarch *gdbarch = a_smob->gdbarch;
60
61 gdbscm_printf (port, "#<%s", arch_smob_name);
62 gdbscm_printf (port, " %s", gdbarch_bfd_arch_info (gdbarch)->printable_name);
63 scm_puts (">", port);
64
65 scm_remember_upto_here_1 (self);
66
67 /* Non-zero means success. */
68 return 1;
69}
70
71/* Low level routine to create a <gdb:arch> object for GDBARCH. */
72
73static SCM
75{
76 arch_smob *a_smob = (arch_smob *)
77 scm_gc_malloc (sizeof (arch_smob), arch_smob_name);
78 SCM a_scm;
79
80 a_smob->gdbarch = gdbarch;
81 a_scm = scm_new_smob (arch_smob_tag, (scm_t_bits) a_smob);
82 gdbscm_init_gsmob (&a_smob->base);
83
84 return a_scm;
85}
86
87/* Return the gdbarch field of A_SMOB. */
88
89struct gdbarch *
91{
92 return a_smob->gdbarch;
93}
94
95/* Return non-zero if SCM is an architecture smob. */
96
97static int
99{
100 return SCM_SMOB_PREDICATE (arch_smob_tag, scm);
101}
102
103/* (arch? object) -> boolean */
104
105static SCM
107{
108 return scm_from_bool (arscm_is_arch (scm));
109}
110
111/* Return the <gdb:arch> object corresponding to GDBARCH.
112 The object is cached in GDBARCH so this is simple. */
113
114SCM
116{
117 SCM arch_scm;
118 void *data = arch_object_data.get (gdbarch);
119 if (data == nullptr)
120 {
121 arch_scm = arscm_make_arch_smob (gdbarch);
122
123 /* This object lasts the duration of the GDB session, so there
124 is no call to scm_gc_unprotect_object for it. */
125 scm_gc_protect_object (arch_scm);
126
127 arch_object_data.set (gdbarch, (void *) arch_scm);
128 }
129 else
130 arch_scm = (SCM) data;
131
132 return arch_scm;
133}
134
135/* Return the <gdb:arch> smob in SELF.
136 Throws an exception if SELF is not a <gdb:arch> object. */
137
138static SCM
139arscm_get_arch_arg_unsafe (SCM self, int arg_pos, const char *func_name)
140{
141 SCM_ASSERT_TYPE (arscm_is_arch (self), self, arg_pos, func_name,
143
144 return self;
145}
146
147/* Return a pointer to the arch smob of SELF.
148 Throws an exception if SELF is not a <gdb:arch> object. */
149
150arch_smob *
151arscm_get_arch_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
152{
153 SCM a_scm = arscm_get_arch_arg_unsafe (self, arg_pos, func_name);
154 arch_smob *a_smob = (arch_smob *) SCM_SMOB_DATA (a_scm);
155
156 return a_smob;
157}
158
159/* Arch methods. */
160
161/* (current-arch) -> <gdb:arch>
162 Return the architecture of the currently selected stack frame,
163 if there is one, or the current target if there isn't. */
164
165static SCM
170
171/* (arch-name <gdb:arch>) -> string
172 Return the name of the architecture as a string value. */
173
174static SCM
176{
177 arch_smob *a_smob
178 = arscm_get_arch_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
179 struct gdbarch *gdbarch = a_smob->gdbarch;
180 const char *name;
181
182 name = (gdbarch_bfd_arch_info (gdbarch))->printable_name;
183
185}
186
187/* (arch-charset <gdb:arch>) -> string */
188
189static SCM
191{
192 arch_smob *a_smob
193 =arscm_get_arch_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
194 struct gdbarch *gdbarch = a_smob->gdbarch;
195
197}
198
199/* (arch-wide-charset <gdb:arch>) -> string */
200
201static SCM
203{
204 arch_smob *a_smob
205 = arscm_get_arch_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
206 struct gdbarch *gdbarch = a_smob->gdbarch;
207
209}
210
211/* Builtin types.
212
213 The order the types are defined here follows the order in
214 struct builtin_type. */
215
216/* Helper routine to return a builtin type for <gdb:arch> object SELF.
217 OFFSET is offsetof (builtin_type, the_type).
218 Throws an exception if SELF is not a <gdb:arch> object. */
219
220static const struct builtin_type *
221gdbscm_arch_builtin_type (SCM self, const char *func_name)
222{
223 arch_smob *a_smob
224 = arscm_get_arch_smob_arg_unsafe (self, SCM_ARG1, func_name);
225 struct gdbarch *gdbarch = a_smob->gdbarch;
226
227 return builtin_type (gdbarch);
228}
229
230/* (arch-void-type <gdb:arch>) -> <gdb:type> */
231
232static SCM
234{
235 struct type *type
237
238 return tyscm_scm_from_type (type);
239}
240
241/* (arch-char-type <gdb:arch>) -> <gdb:type> */
242
243static SCM
245{
246 struct type *type
248
249 return tyscm_scm_from_type (type);
250}
251
252/* (arch-short-type <gdb:arch>) -> <gdb:type> */
253
254static SCM
256{
257 struct type *type
259
260 return tyscm_scm_from_type (type);
261}
262
263/* (arch-int-type <gdb:arch>) -> <gdb:type> */
264
265static SCM
267{
268 struct type *type
270
271 return tyscm_scm_from_type (type);
272}
273
274/* (arch-long-type <gdb:arch>) -> <gdb:type> */
275
276static SCM
278{
279 struct type *type
281
282 return tyscm_scm_from_type (type);
283}
284
285/* (arch-schar-type <gdb:arch>) -> <gdb:type> */
286
287static SCM
289{
290 struct type *type
292
293 return tyscm_scm_from_type (type);
294}
295
296/* (arch-uchar-type <gdb:arch>) -> <gdb:type> */
297
298static SCM
300{
301 struct type *type
303
304 return tyscm_scm_from_type (type);
305}
306
307/* (arch-ushort-type <gdb:arch>) -> <gdb:type> */
308
309static SCM
317
318/* (arch-uint-type <gdb:arch>) -> <gdb:type> */
319
320static SCM
322{
323 struct type *type
325
326 return tyscm_scm_from_type (type);
327}
328
329/* (arch-ulong-type <gdb:arch>) -> <gdb:type> */
330
331static SCM
333{
334 struct type *type
336
337 return tyscm_scm_from_type (type);
338}
339
340/* (arch-float-type <gdb:arch>) -> <gdb:type> */
341
342static SCM
344{
345 struct type *type
347
348 return tyscm_scm_from_type (type);
349}
350
351/* (arch-double-type <gdb:arch>) -> <gdb:type> */
352
353static SCM
355{
356 struct type *type
358
359 return tyscm_scm_from_type (type);
360}
361
362/* (arch-longdouble-type <gdb:arch>) -> <gdb:type> */
363
364static SCM
372
373/* (arch-bool-type <gdb:arch>) -> <gdb:type> */
374
375static SCM
377{
378 struct type *type
380
381 return tyscm_scm_from_type (type);
382}
383
384/* (arch-longlong-type <gdb:arch>) -> <gdb:type> */
385
386static SCM
388{
389 struct type *type
391
392 return tyscm_scm_from_type (type);
393}
394
395/* (arch-ulonglong-type <gdb:arch>) -> <gdb:type> */
396
397static SCM
405
406/* (arch-int8-type <gdb:arch>) -> <gdb:type> */
407
408static SCM
410{
411 struct type *type
413
414 return tyscm_scm_from_type (type);
415}
416
417/* (arch-uint8-type <gdb:arch>) -> <gdb:type> */
418
419static SCM
421{
422 struct type *type
424
425 return tyscm_scm_from_type (type);
426}
427
428/* (arch-int16-type <gdb:arch>) -> <gdb:type> */
429
430static SCM
432{
433 struct type *type
435
436 return tyscm_scm_from_type (type);
437}
438
439/* (arch-uint16-type <gdb:arch>) -> <gdb:type> */
440
441static SCM
443{
444 struct type *type
446
447 return tyscm_scm_from_type (type);
448}
449
450/* (arch-int32-type <gdb:arch>) -> <gdb:type> */
451
452static SCM
454{
455 struct type *type
457
458 return tyscm_scm_from_type (type);
459}
460
461/* (arch-uint32-type <gdb:arch>) -> <gdb:type> */
462
463static SCM
465{
466 struct type *type
468
469 return tyscm_scm_from_type (type);
470}
471
472/* (arch-int64-type <gdb:arch>) -> <gdb:type> */
473
474static SCM
476{
477 struct type *type
479
480 return tyscm_scm_from_type (type);
481}
482
483/* (arch-uint64-type <gdb:arch>) -> <gdb:type> */
484
485static SCM
487{
488 struct type *type
490
491 return tyscm_scm_from_type (type);
492}
493
494/* Initialize the Scheme architecture support. */
495
497{
498 { "arch?", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_p),
499 "\
500Return #t if the object is a <gdb:arch> object." },
501
502 { "current-arch", 0, 0, 0, as_a_scm_t_subr (gdbscm_current_arch),
503 "\
504Return the <gdb:arch> object representing the architecture of the\n\
505currently selected stack frame, if there is one, or the architecture of the\n\
506current target if there isn't.\n\
507\n\
508 Arguments: none" },
509
510 { "arch-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_name),
511 "\
512Return the name of the architecture." },
513
514 { "arch-charset", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_charset),
515 "\
516Return name of target character set as a string." },
517
518 { "arch-wide-charset", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_wide_charset),
519 "\
520Return name of target wide character set as a string." },
521
522 { "arch-void-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_void_type),
523 "\
524Return the <gdb:type> object for the \"void\" type\n\
525of the architecture." },
526
527 { "arch-char-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_char_type),
528 "\
529Return the <gdb:type> object for the \"char\" type\n\
530of the architecture." },
531
532 { "arch-short-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_short_type),
533 "\
534Return the <gdb:type> object for the \"short\" type\n\
535of the architecture." },
536
537 { "arch-int-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_int_type),
538 "\
539Return the <gdb:type> object for the \"int\" type\n\
540of the architecture." },
541
542 { "arch-long-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_long_type),
543 "\
544Return the <gdb:type> object for the \"long\" type\n\
545of the architecture." },
546
547 { "arch-schar-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_schar_type),
548 "\
549Return the <gdb:type> object for the \"signed char\" type\n\
550of the architecture." },
551
552 { "arch-uchar-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uchar_type),
553 "\
554Return the <gdb:type> object for the \"unsigned char\" type\n\
555of the architecture." },
556
557 { "arch-ushort-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_ushort_type),
558 "\
559Return the <gdb:type> object for the \"unsigned short\" type\n\
560of the architecture." },
561
562 { "arch-uint-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uint_type),
563 "\
564Return the <gdb:type> object for the \"unsigned int\" type\n\
565of the architecture." },
566
567 { "arch-ulong-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_ulong_type),
568 "\
569Return the <gdb:type> object for the \"unsigned long\" type\n\
570of the architecture." },
571
572 { "arch-float-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_float_type),
573 "\
574Return the <gdb:type> object for the \"float\" type\n\
575of the architecture." },
576
577 { "arch-double-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_double_type),
578 "\
579Return the <gdb:type> object for the \"double\" type\n\
580of the architecture." },
581
582 { "arch-longdouble-type", 1, 0, 0,
584 "\
585Return the <gdb:type> object for the \"long double\" type\n\
586of the architecture." },
587
588 { "arch-bool-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_bool_type),
589 "\
590Return the <gdb:type> object for the \"bool\" type\n\
591of the architecture." },
592
593 { "arch-longlong-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_longlong_type),
594 "\
595Return the <gdb:type> object for the \"long long\" type\n\
596of the architecture." },
597
598 { "arch-ulonglong-type", 1, 0, 0,
600 "\
601Return the <gdb:type> object for the \"unsigned long long\" type\n\
602of the architecture." },
603
604 { "arch-int8-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_int8_type),
605 "\
606Return the <gdb:type> object for the \"int8\" type\n\
607of the architecture." },
608
609 { "arch-uint8-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uint8_type),
610 "\
611Return the <gdb:type> object for the \"uint8\" type\n\
612of the architecture." },
613
614 { "arch-int16-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_int16_type),
615 "\
616Return the <gdb:type> object for the \"int16\" type\n\
617of the architecture." },
618
619 { "arch-uint16-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uint16_type),
620 "\
621Return the <gdb:type> object for the \"uint16\" type\n\
622of the architecture." },
623
624 { "arch-int32-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_int32_type),
625 "\
626Return the <gdb:type> object for the \"int32\" type\n\
627of the architecture." },
628
629 { "arch-uint32-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uint32_type),
630 "\
631Return the <gdb:type> object for the \"uint32\" type\n\
632of the architecture." },
633
634 { "arch-int64-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_int64_type),
635 "\
636Return the <gdb:type> object for the \"int64\" type\n\
637of the architecture." },
638
639 { "arch-uint64-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_arch_uint64_type),
640 "\
641Return the <gdb:type> object for the \"uint64\" type\n\
642of the architecture." },
643
645};
646
647void
const char *const name
static struct parser_state * pstate
Definition ada-exp.c:101
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
const char * target_wide_charset(struct gdbarch *gdbarch)
Definition charset.c:432
const char * target_charset(struct gdbarch *gdbarch)
Definition charset.c:424
void set(unsigned key, void *datum)
Definition registry.h:204
void * get(unsigned key)
Definition registry.h:211
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
Definition gdbarch.c:1387
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
#define END_FUNCTIONS
void gdbscm_init_gsmob(gdb_smob *base)
Definition scm-gsmob.c:140
SCM tyscm_scm_from_type(struct type *type)
Definition scm-type.c:313
void gdbscm_printf(SCM port, const char *format,...) ATTRIBUTE_PRINTF(2
static SCM scm_new_smob(scm_t_bits tc, scm_t_bits data)
void gdbscm_define_functions(const scheme_function *, int is_public)
Definition scm-utils.c:44
scm_t_bits gdbscm_make_smob_type(const char *name, size_t size)
Definition scm-gsmob.c:103
static scm_t_subr as_a_scm_t_subr(SCM(*func)(void))
#define FUNC_NAME
SCM gdbscm_scm_from_c_string(const char *string)
Definition scm-string.c:45
static SCM gdbscm_arch_longlong_type(SCM self)
Definition scm-arch.c:387
static const registry< gdbarch >::key< void, gdb::noop_deleter< void > > arch_object_data
Definition scm-arch.c:47
static SCM gdbscm_current_arch(void)
Definition scm-arch.c:166
arch_smob * arscm_get_arch_smob_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition scm-arch.c:151
static SCM gdbscm_arch_int32_type(SCM self)
Definition scm-arch.c:453
static SCM gdbscm_arch_uint_type(SCM self)
Definition scm-arch.c:321
static SCM gdbscm_arch_int16_type(SCM self)
Definition scm-arch.c:431
static SCM gdbscm_arch_short_type(SCM self)
Definition scm-arch.c:255
static SCM gdbscm_arch_int8_type(SCM self)
Definition scm-arch.c:409
static SCM gdbscm_arch_uchar_type(SCM self)
Definition scm-arch.c:299
static int arscm_print_arch_smob(SCM self, SCM port, scm_print_state *pstate)
Definition scm-arch.c:56
static SCM gdbscm_arch_wide_charset(SCM self)
Definition scm-arch.c:202
static SCM gdbscm_arch_void_type(SCM self)
Definition scm-arch.c:233
static SCM gdbscm_arch_int64_type(SCM self)
Definition scm-arch.c:475
static SCM gdbscm_arch_schar_type(SCM self)
Definition scm-arch.c:288
static const struct builtin_type * gdbscm_arch_builtin_type(SCM self, const char *func_name)
Definition scm-arch.c:221
static SCM gdbscm_arch_uint64_type(SCM self)
Definition scm-arch.c:486
static SCM gdbscm_arch_name(SCM self)
Definition scm-arch.c:175
static const char arch_smob_name[]
Definition scm-arch.c:39
static SCM gdbscm_arch_p(SCM scm)
Definition scm-arch.c:106
static SCM gdbscm_arch_ulonglong_type(SCM self)
Definition scm-arch.c:398
static const scheme_function arch_functions[]
Definition scm-arch.c:496
SCM arscm_scm_from_arch(struct gdbarch *gdbarch)
Definition scm-arch.c:115
static SCM arscm_make_arch_smob(struct gdbarch *gdbarch)
Definition scm-arch.c:74
static SCM gdbscm_arch_long_type(SCM self)
Definition scm-arch.c:277
static SCM gdbscm_arch_ushort_type(SCM self)
Definition scm-arch.c:310
void gdbscm_initialize_arches(void)
Definition scm-arch.c:648
static SCM gdbscm_arch_float_type(SCM self)
Definition scm-arch.c:343
static SCM gdbscm_arch_longdouble_type(SCM self)
Definition scm-arch.c:365
static SCM arscm_get_arch_arg_unsafe(SCM self, int arg_pos, const char *func_name)
Definition scm-arch.c:139
static SCM gdbscm_arch_uint32_type(SCM self)
Definition scm-arch.c:464
static int arscm_is_arch(SCM)
Definition scm-arch.c:98
static SCM gdbscm_arch_double_type(SCM self)
Definition scm-arch.c:354
static SCM gdbscm_arch_char_type(SCM self)
Definition scm-arch.c:244
struct gdbarch * arscm_get_gdbarch(arch_smob *a_smob)
Definition scm-arch.c:90
static SCM gdbscm_arch_int_type(SCM self)
Definition scm-arch.c:266
static SCM gdbscm_arch_uint8_type(SCM self)
Definition scm-arch.c:420
static SCM gdbscm_arch_uint16_type(SCM self)
Definition scm-arch.c:442
static SCM gdbscm_arch_ulong_type(SCM self)
Definition scm-arch.c:332
static SCM gdbscm_arch_bool_type(SCM self)
Definition scm-arch.c:376
static SCM gdbscm_arch_charset(SCM self)
Definition scm-arch.c:190
static scm_t_bits arch_smob_tag
Definition scm-arch.c:42
gdb_smob base
Definition scm-arch.c:34
struct gdbarch * gdbarch
Definition scm-arch.c:36
struct type * builtin_signed_char
Definition gdbtypes.h:2082
struct type * builtin_long_long
Definition gdbtypes.h:2096
struct type * builtin_uint16
Definition gdbtypes.h:2116
struct type * builtin_double
Definition gdbtypes.h:2090
struct type * builtin_int8
Definition gdbtypes.h:2113
struct type * builtin_long
Definition gdbtypes.h:2081
struct type * builtin_bool
Definition gdbtypes.h:2095
struct type * builtin_unsigned_char
Definition gdbtypes.h:2083
struct type * builtin_long_double
Definition gdbtypes.h:2091
struct type * builtin_unsigned_long_long
Definition gdbtypes.h:2097
struct type * builtin_uint32
Definition gdbtypes.h:2120
struct type * builtin_uint64
Definition gdbtypes.h:2122
struct type * builtin_short
Definition gdbtypes.h:2079
struct type * builtin_int64
Definition gdbtypes.h:2121
struct type * builtin_char
Definition gdbtypes.h:2078
struct type * builtin_int
Definition gdbtypes.h:2080
struct type * builtin_int32
Definition gdbtypes.h:2119
struct type * builtin_unsigned_short
Definition gdbtypes.h:2084
struct type * builtin_unsigned_int
Definition gdbtypes.h:2085
struct type * builtin_uint8
Definition gdbtypes.h:2114
struct type * builtin_unsigned_long
Definition gdbtypes.h:2086
struct type * builtin_int16
Definition gdbtypes.h:2115
struct type * builtin_void
Definition gdbtypes.h:2077
struct type * builtin_float
Definition gdbtypes.h:2089