File: foundry-debugger-trap-params.c

package info (click to toggle)
foundry 1.1~beta-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,552 kB
  • sloc: ansic: 167,487; xml: 417; makefile: 21; sh: 19; javascript: 10
file content (543 lines) | stat: -rw-r--r-- 17,494 bytes parent folder | download | duplicates (2)
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
/* foundry-debugger-trap-params.c
 *
 * Copyright 2025 Christian Hergert <chergert@redhat.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This library 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
 * Lesser 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/>.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include "foundry-debugger-trap-params.h"

/**
 * FoundryDebuggerTrapParams:
 *
 * Represents parameters for debugger traps and breakpoints.
 *
 * FoundryDebuggerTrapParams provides functionality for configuring
 * debugger traps including breakpoints, watchpoints, and other
 * debugging stops. It includes location information, access patterns,
 * and disposition settings for precise control over debugging behavior.
 */

struct _FoundryDebuggerTrapParams
{
  GObject                         parent_instance;
  char                           *path;
  char                           *function;
  char                           *thread_id;
  char                           *stack_frame_id;
  guint64                         instruction_pointer;
  guint                           line;
  guint                           line_offset;
  FoundryDebuggerTrapDisposition  disposition : 4;
  FoundryDebuggerTrapKind         kind : 4;
  FoundryDebuggerWatchAccess      access : 4;
};

enum {
  PROP_0,
  PROP_ACCESS,
  PROP_INSTRUCTION_POINTER,
  PROP_DISPOSITION,
  PROP_FUNCTION,
  PROP_KIND,
  PROP_LINE,
  PROP_LINE_OFFSET,
  PROP_PATH,
  PROP_STACK_FRAME_ID,
  PROP_THREAD_ID,
  N_PROPS
};

G_DEFINE_FINAL_TYPE (FoundryDebuggerTrapParams, foundry_debugger_trap_params, G_TYPE_OBJECT)

static GParamSpec *properties[N_PROPS];

static void
foundry_debugger_trap_params_finalize (GObject *object)
{
  FoundryDebuggerTrapParams *self = (FoundryDebuggerTrapParams *)object;

  g_clear_pointer (&self->path, g_free);
  g_clear_pointer (&self->function, g_free);
  g_clear_pointer (&self->thread_id, g_free);
  g_clear_pointer (&self->stack_frame_id, g_free);

  G_OBJECT_CLASS (foundry_debugger_trap_params_parent_class)->finalize (object);
}

static void
foundry_debugger_trap_params_get_property (GObject    *object,
                                           guint       prop_id,
                                           GValue     *value,
                                           GParamSpec *pspec)
{
  FoundryDebuggerTrapParams *self = FOUNDRY_DEBUGGER_TRAP_PARAMS (object);

  switch (prop_id)
    {
    case PROP_ACCESS:
      g_value_set_flags (value, foundry_debugger_trap_params_get_access (self));
      break;

    case PROP_DISPOSITION:
      g_value_set_enum (value, foundry_debugger_trap_params_get_disposition (self));
      break;

    case PROP_FUNCTION:
      g_value_take_string (value, foundry_debugger_trap_params_dup_function (self));
      break;

    case PROP_INSTRUCTION_POINTER:
      g_value_set_uint64 (value, foundry_debugger_trap_params_get_instruction_pointer (self));
      break;

    case PROP_KIND:
      g_value_set_enum (value, foundry_debugger_trap_params_get_kind (self));
      break;

    case PROP_LINE:
      g_value_set_uint (value, foundry_debugger_trap_params_get_line (self));
      break;

    case PROP_LINE_OFFSET:
      g_value_set_uint (value, foundry_debugger_trap_params_get_line_offset (self));
      break;

    case PROP_PATH:
      g_value_take_string (value, foundry_debugger_trap_params_dup_path (self));
      break;

    case PROP_STACK_FRAME_ID:
      g_value_take_string (value, foundry_debugger_trap_params_dup_stack_frame_id (self));
      break;

    case PROP_THREAD_ID:
      g_value_take_string (value, foundry_debugger_trap_params_dup_thread_id (self));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
foundry_debugger_trap_params_set_property (GObject      *object,
                                           guint         prop_id,
                                           const GValue *value,
                                           GParamSpec   *pspec)
{
  FoundryDebuggerTrapParams *self = FOUNDRY_DEBUGGER_TRAP_PARAMS (object);

  switch (prop_id)
    {
    case PROP_ACCESS:
      foundry_debugger_trap_params_set_access (self, g_value_get_flags (value));
      break;

    case PROP_DISPOSITION:
      foundry_debugger_trap_params_set_disposition (self, g_value_get_enum (value));
      break;

    case PROP_FUNCTION:
      foundry_debugger_trap_params_set_function (self, g_value_get_string (value));
      break;

    case PROP_INSTRUCTION_POINTER:
      foundry_debugger_trap_params_set_instruction_pointer (self, g_value_get_uint64 (value));
      break;

    case PROP_KIND:
      foundry_debugger_trap_params_set_kind (self, g_value_get_enum (value));
      break;

    case PROP_LINE:
      foundry_debugger_trap_params_set_line (self, g_value_get_uint (value));
      break;

    case PROP_LINE_OFFSET:
      foundry_debugger_trap_params_set_line_offset (self, g_value_get_uint (value));
      break;

    case PROP_PATH:
      foundry_debugger_trap_params_set_path (self, g_value_get_string (value));
      break;

    case PROP_STACK_FRAME_ID:
      foundry_debugger_trap_params_set_stack_frame_id (self, g_value_get_string (value));
      break;

    case PROP_THREAD_ID:
      foundry_debugger_trap_params_set_thread_id (self, g_value_get_string (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
foundry_debugger_trap_params_class_init (FoundryDebuggerTrapParamsClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = foundry_debugger_trap_params_finalize;
  object_class->get_property = foundry_debugger_trap_params_get_property;
  object_class->set_property = foundry_debugger_trap_params_set_property;

  properties[PROP_ACCESS] =
    g_param_spec_flags ("access", NULL, NULL,
                        FOUNDRY_TYPE_DEBUGGER_WATCH_ACCESS,
                        FOUNDRY_DEBUGGER_WATCH_NONE,
                        (G_PARAM_READWRITE |
                         G_PARAM_EXPLICIT_NOTIFY |
                         G_PARAM_STATIC_STRINGS));

  properties[PROP_DISPOSITION] =
    g_param_spec_enum ("disposition", NULL, NULL,
                       FOUNDRY_TYPE_DEBUGGER_TRAP_DISPOSITION,
                       FOUNDRY_DEBUGGER_TRAP_KEEP,
                       (G_PARAM_READWRITE |
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS));

  properties[PROP_FUNCTION] =
    g_param_spec_string ("function", NULL, NULL,
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_EXPLICIT_NOTIFY |
                          G_PARAM_STATIC_STRINGS));

  properties[PROP_INSTRUCTION_POINTER] =
    g_param_spec_uint64 ("instruction-pointer", NULL, NULL,
                         0, G_MAXUINT64, 0,
                         (G_PARAM_READWRITE |
                          G_PARAM_EXPLICIT_NOTIFY |
                          G_PARAM_STATIC_STRINGS));

  properties[PROP_KIND] =
    g_param_spec_enum ("kind", NULL, NULL,
                       FOUNDRY_TYPE_DEBUGGER_TRAP_KIND,
                       FOUNDRY_DEBUGGER_TRAP_KIND_BREAKPOINT,
                       (G_PARAM_READWRITE |
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS));

  properties[PROP_LINE] =
    g_param_spec_uint ("line", NULL, NULL,
                       0, G_MAXUINT, 0,
                       (G_PARAM_READWRITE |
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS));

  properties[PROP_LINE_OFFSET] =
    g_param_spec_uint ("line-offset", NULL, NULL,
                       0, G_MAXUINT, 0,
                       (G_PARAM_READWRITE |
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS));

  properties[PROP_PATH] =
    g_param_spec_string ("path", NULL, NULL,
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_EXPLICIT_NOTIFY |
                          G_PARAM_STATIC_STRINGS));

  properties[PROP_STACK_FRAME_ID] =
    g_param_spec_string ("stack-frame-id", NULL, NULL,
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_EXPLICIT_NOTIFY |
                          G_PARAM_STATIC_STRINGS));

  properties[PROP_THREAD_ID] =
    g_param_spec_string ("thread-id", NULL, NULL,
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_EXPLICIT_NOTIFY |
                          G_PARAM_STATIC_STRINGS));

  g_object_class_install_properties (object_class, N_PROPS, properties);
}

static void
foundry_debugger_trap_params_init (FoundryDebuggerTrapParams *self)
{
}

char *
foundry_debugger_trap_params_dup_path (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), NULL);

  return g_strdup (self->path);
}

guint
foundry_debugger_trap_params_get_line (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->line;
}

guint
foundry_debugger_trap_params_get_line_offset (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->line_offset;
}

FoundryDebuggerTrapDisposition
foundry_debugger_trap_params_get_disposition (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->disposition;
}

guint64
foundry_debugger_trap_params_get_instruction_pointer (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->instruction_pointer;
}

char *
foundry_debugger_trap_params_dup_function (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), NULL);

  return g_strdup (self->function);
}

char *
foundry_debugger_trap_params_dup_stack_frame_id (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), NULL);

  return g_strdup (self->stack_frame_id);
}

char *
foundry_debugger_trap_params_dup_thread_id (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), NULL);

  return g_strdup (self->thread_id);
}

void
foundry_debugger_trap_params_set_path (FoundryDebuggerTrapParams *self,
                                       const char                *path)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (g_set_str (&self->path, path))
    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PATH]);
}

void
foundry_debugger_trap_params_set_line (FoundryDebuggerTrapParams *self,
                                       guint                      line)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (line != self->line)
    {
      self->line = line;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LINE]);
    }
}

void
foundry_debugger_trap_params_set_line_offset (FoundryDebuggerTrapParams *self,
                                              guint                      line_offset)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (line_offset != self->line_offset)
    {
      self->line_offset = line_offset;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LINE_OFFSET]);
    }
}

void
foundry_debugger_trap_params_set_disposition (FoundryDebuggerTrapParams      *self,
                                              FoundryDebuggerTrapDisposition  disposition)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));
  g_return_if_fail (disposition <= FOUNDRY_DEBUGGER_TRAP_REMOVE_NEXT_STOP);

  if (disposition != self->disposition)
    {
      self->disposition = disposition;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DISPOSITION]);
    }
}

void
foundry_debugger_trap_params_set_stack_frame_id (FoundryDebuggerTrapParams *self,
                                                 const char                *stack_frame_id)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (g_set_str (&self->stack_frame_id, stack_frame_id))
    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STACK_FRAME_ID]);
}

void
foundry_debugger_trap_params_set_thread_id (FoundryDebuggerTrapParams *self,
                                            const char                *thread_id)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (g_set_str (&self->thread_id, thread_id))
    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_THREAD_ID]);
}

void
foundry_debugger_trap_params_set_function (FoundryDebuggerTrapParams *self,
                                           const char                *function)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (g_set_str (&self->function, function))
    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FUNCTION]);
}

void
foundry_debugger_trap_params_set_instruction_pointer (FoundryDebuggerTrapParams *self,
                                                      guint64                    instruction_pointer)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (instruction_pointer != self->instruction_pointer)
    {
      self->instruction_pointer = instruction_pointer;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INSTRUCTION_POINTER]);
    }
}

FoundryDebuggerTrapKind
foundry_debugger_trap_params_get_kind (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->kind;
}

void
foundry_debugger_trap_params_set_kind (FoundryDebuggerTrapParams *self,
                                       FoundryDebuggerTrapKind    kind)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (kind != self->kind)
    {
      self->kind = kind;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_KIND]);
    }
}

FoundryDebuggerWatchAccess
foundry_debugger_trap_params_get_access (FoundryDebuggerTrapParams *self)
{
  g_return_val_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), 0);

  return self->access;
}

void
foundry_debugger_trap_params_set_access (FoundryDebuggerTrapParams  *self,
                                         FoundryDebuggerWatchAccess  access)
{
  g_return_if_fail (FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self));

  if (access != self->access)
    {
      self->access = access;
      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_KIND]);
    }
}

/**
 * foundry_debugger_trap_params_new:
 *
 * Returns: (transfer full):
 *
 * Since: 1.1
 */
FoundryDebuggerTrapParams *
foundry_debugger_trap_params_new (void)
{
  return g_object_new (FOUNDRY_TYPE_DEBUGGER_TRAP_PARAMS, NULL);
}

/**
 * foundry_debugger_trap_params_copy:
 * @self: (nullable): a [class@Foundry.DebuggerTrapParams]
 *
 * Returns: (transfer full) (nullable):
 */
FoundryDebuggerTrapParams *
foundry_debugger_trap_params_copy (FoundryDebuggerTrapParams *self)
{
  FoundryDebuggerTrapParams *copy;

  g_return_val_if_fail (!self || FOUNDRY_IS_DEBUGGER_TRAP_PARAMS (self), NULL);

  if (self == NULL)
    return NULL;

  copy = foundry_debugger_trap_params_new ();

  g_set_str (&copy->path, self->path);
  g_set_str (&copy->function, self->function);
  g_set_str (&copy->thread_id, self->thread_id);
  g_set_str (&copy->stack_frame_id, self->stack_frame_id);

  copy->instruction_pointer = self->instruction_pointer;
  copy->line = self->line;
  copy->line_offset = self->line_offset;
  copy->disposition = self->disposition;
  copy->kind = self->kind;
  copy->access = self->access;

  return copy;
}

G_DEFINE_ENUM_TYPE (FoundryDebuggerTrapDisposition, foundry_debugger_trap_disposition,
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_KEEP, "keep"),
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_DISABLE, "disable"),
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_REMOVE_NEXT_HIT, "next-hit"),
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_REMOVE_NEXT_STOP, "next-stop"))

G_DEFINE_ENUM_TYPE (FoundryDebuggerTrapKind, foundry_debugger_trap_kind,
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_KIND_BREAKPOINT, "breakpoint"),
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_KIND_COUNTPOINT, "countpoint"),
                    G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_TRAP_KIND_WATCHPOINT, "watchpoint"))

G_DEFINE_FLAGS_TYPE (FoundryDebuggerWatchAccess, foundry_debugger_watch_access,
                     G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_WATCH_NONE, "none"),
                     G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_WATCH_READ, "read"),
                     G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_WATCH_WRITE, "write"),
                     G_DEFINE_ENUM_VALUE (FOUNDRY_DEBUGGER_WATCH_READWRITE, "readwrite"))