2001-07-14 23:53:59 +00:00
|
|
|
/*
|
|
|
|
pr_debug.c
|
|
|
|
|
|
|
|
progs debugging
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@tanwiha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@tanwiha.org>
|
|
|
|
Date: 2001/7/13
|
|
|
|
|
|
|
|
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 2
|
|
|
|
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, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2007-04-28 01:40:08 +00:00
|
|
|
#include <ctype.h>
|
2007-05-08 02:04:47 +00:00
|
|
|
#include <sys/types.h>
|
2001-07-14 23:53:59 +00:00
|
|
|
#include <stdlib.h>
|
2022-01-05 13:32:07 +00:00
|
|
|
#include <inttypes.h>
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2021-06-08 07:54:04 +00:00
|
|
|
#include "QF/fbsearch.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/cvar.h"
|
2002-10-23 20:42:02 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/hash.h"
|
2022-04-30 01:06:01 +00:00
|
|
|
#include "QF/heapsort.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2007-05-08 02:04:47 +00:00
|
|
|
#include "QF/script.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/sys.h"
|
2022-01-27 01:56:57 +00:00
|
|
|
#include "QF/va.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/zone.h"
|
|
|
|
|
2022-01-08 15:26:52 +00:00
|
|
|
#include "QF/progs/pr_debug.h"
|
|
|
|
#include "QF/progs/pr_type.h"
|
2022-01-30 01:47:37 +00:00
|
|
|
#include "QF/simd/types.h"
|
2022-01-08 15:26:52 +00:00
|
|
|
|
2003-02-24 16:01:52 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
typedef struct {
|
|
|
|
char *text;
|
|
|
|
size_t len;
|
|
|
|
} line_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
char *text;
|
2020-02-21 12:17:28 +00:00
|
|
|
off_t size;
|
2001-07-14 23:53:59 +00:00
|
|
|
line_t *lines;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t num_lines;
|
2002-06-11 17:24:37 +00:00
|
|
|
progs_t *pr;
|
2001-07-14 23:53:59 +00:00
|
|
|
} file_t;
|
|
|
|
|
2020-04-04 03:50:25 +00:00
|
|
|
typedef struct compunit_s {
|
|
|
|
const char *file;
|
|
|
|
pr_compunit_t *unit;
|
|
|
|
} compunit_t;
|
|
|
|
|
2021-06-08 07:54:04 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *file;
|
|
|
|
pr_uint_t line;
|
|
|
|
} func_key_t;
|
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
typedef struct prdeb_resources_s {
|
|
|
|
progs_t *pr;
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_t *string;
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_t *dva;
|
|
|
|
dstring_t *line;
|
|
|
|
dstring_t *dstr;
|
2022-01-27 01:56:57 +00:00
|
|
|
va_ctx_t *va;
|
2020-02-25 11:07:29 +00:00
|
|
|
const char *debugfile;
|
2020-04-03 13:35:55 +00:00
|
|
|
pr_debug_header_t *debug;
|
|
|
|
pr_auxfunction_t *auxfunctions;
|
|
|
|
pr_auxfunction_t **auxfunction_map;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t *sorted_functions;
|
2020-04-03 13:35:55 +00:00
|
|
|
pr_lineno_t *linenos;
|
2020-02-25 11:07:29 +00:00
|
|
|
pr_def_t *local_defs;
|
2020-02-25 11:45:36 +00:00
|
|
|
pr_def_t *type_encodings_def;
|
2020-03-14 11:44:43 +00:00
|
|
|
qfot_type_t void_type;
|
|
|
|
qfot_type_t *type_encodings[ev_type_count];
|
2020-04-04 03:50:25 +00:00
|
|
|
pr_def_t *debug_defs;
|
|
|
|
pr_type_t *debug_data;
|
|
|
|
hashtab_t *debug_syms;
|
|
|
|
hashtab_t *compunits; // by source file
|
|
|
|
PR_RESMAP (compunit_t) compmap; // handy allocation/freeing
|
2020-04-03 13:39:27 +00:00
|
|
|
hashtab_t *file_hash;
|
2020-02-25 11:07:29 +00:00
|
|
|
} prdeb_resources_t;
|
2020-02-23 09:56:30 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
progs_t *pr;
|
|
|
|
dstring_t *dstr;
|
|
|
|
} pr_debug_data_t;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int pr_debug;
|
|
|
|
static cvar_t pr_debug_cvar = {
|
|
|
|
.name = "pr_debug",
|
|
|
|
.description =
|
|
|
|
"enable progs debugging",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &pr_debug },
|
|
|
|
};
|
|
|
|
char *pr_source_path;
|
|
|
|
static cvar_t pr_source_path_cvar = {
|
|
|
|
.name = "pr_source_path",
|
|
|
|
.description =
|
|
|
|
"where to look (within gamedir) for source files",
|
|
|
|
.default_value = ".",
|
|
|
|
.flags = CVAR_NONE,
|
2022-04-24 11:04:06 +00:00
|
|
|
.value = { .type = 0, .value = &pr_source_path },
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
2020-04-03 13:39:27 +00:00
|
|
|
static char *source_path_string;
|
|
|
|
static char **source_paths;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void pr_debug_struct_view (qfot_type_t *type, pr_type_t *value,
|
|
|
|
void *_data);
|
|
|
|
static void pr_debug_union_view (qfot_type_t *type, pr_type_t *value,
|
|
|
|
void *_data);
|
|
|
|
static void pr_debug_enum_view (qfot_type_t *type, pr_type_t *value,
|
|
|
|
void *_data);
|
|
|
|
static void pr_debug_array_view (qfot_type_t *type, pr_type_t *value,
|
|
|
|
void *_data);
|
|
|
|
static void pr_debug_class_view (qfot_type_t *type, pr_type_t *value,
|
|
|
|
void *_data);
|
2022-01-30 01:47:37 +00:00
|
|
|
#define EV_TYPE(t) \
|
|
|
|
static void pr_debug_##t##_view (qfot_type_t *type, pr_type_t *value, \
|
|
|
|
void *_data);
|
|
|
|
#include "QF/progs/pr_type_names.h"
|
2020-02-23 09:56:30 +00:00
|
|
|
|
|
|
|
static type_view_t raw_type_view = {
|
|
|
|
pr_debug_struct_view,
|
|
|
|
pr_debug_union_view,
|
|
|
|
pr_debug_enum_view,
|
|
|
|
pr_debug_array_view,
|
|
|
|
pr_debug_class_view,
|
2022-01-30 01:47:37 +00:00
|
|
|
#define EV_TYPE(t) \
|
|
|
|
pr_debug_##t##_view,
|
|
|
|
#include "QF/progs/pr_type_names.h"
|
2020-02-23 09:56:30 +00:00
|
|
|
};
|
2001-09-10 12:56:23 +00:00
|
|
|
|
2001-10-08 03:46:44 +00:00
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
file_get_key (const void *_f, void *unused)
|
2001-10-08 03:46:44 +00:00
|
|
|
{
|
|
|
|
return ((file_t*)_f)->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_free (void *_f, void *unused)
|
|
|
|
{
|
2002-06-11 17:24:37 +00:00
|
|
|
file_t *f = (file_t*)_f;
|
|
|
|
progs_t *pr = f->pr;
|
|
|
|
|
2001-10-08 03:46:44 +00:00
|
|
|
free (f->lines);
|
2002-06-11 17:24:37 +00:00
|
|
|
((progs_t *) pr)->free_progs_mem (pr, f->text);
|
2001-10-08 03:46:44 +00:00
|
|
|
free (f->name);
|
|
|
|
free (f);
|
|
|
|
}
|
|
|
|
|
2020-04-04 03:50:25 +00:00
|
|
|
static const char *
|
|
|
|
def_get_key (const void *d, void *p)
|
|
|
|
{
|
|
|
|
__auto_type def = (pr_def_t *) d;
|
|
|
|
__auto_type pr = (progs_t *) p;
|
|
|
|
return PR_GetString (pr, def->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
compunit_get_key (const void *cu, void *p)
|
|
|
|
{
|
|
|
|
__auto_type compunit = (compunit_t *) cu;
|
|
|
|
return compunit->file;
|
|
|
|
}
|
|
|
|
|
2003-03-12 22:31:44 +00:00
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
source_path_f (void *data, const cvar_t *cvar)
|
2003-03-12 22:31:44 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *s;
|
|
|
|
|
2020-03-04 12:09:36 +00:00
|
|
|
if (source_path_string) {
|
2003-03-12 22:31:44 +00:00
|
|
|
free (source_path_string);
|
2020-03-04 12:09:36 +00:00
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
source_path_string = strdup (pr_source_path);
|
2020-03-04 12:09:36 +00:00
|
|
|
if (source_paths) {
|
2003-03-12 22:31:44 +00:00
|
|
|
free (source_paths);
|
2020-03-04 12:09:36 +00:00
|
|
|
}
|
|
|
|
// i starts at 2 because an empty path is equivalent to "." and the
|
|
|
|
// list is null terminated
|
|
|
|
for (i = 2, s = source_path_string; *s; s++) {
|
|
|
|
if (*s == ';') {
|
2003-03-12 22:31:44 +00:00
|
|
|
i++;
|
2020-03-04 12:09:36 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-07 11:00:57 +00:00
|
|
|
source_paths = malloc (i * sizeof (char *));
|
2003-03-12 22:31:44 +00:00
|
|
|
source_paths[0] = source_path_string;
|
2020-03-04 12:09:36 +00:00
|
|
|
// i starts at one because the first path is in 0 and any additional
|
|
|
|
// paths come after, then the null terminator
|
|
|
|
for (i = 1, s = source_path_string; *s; s++) {
|
2003-03-12 22:31:44 +00:00
|
|
|
if (*s == ';') {
|
2020-03-04 12:10:23 +00:00
|
|
|
*s = 0;
|
|
|
|
source_paths[i++] = s + 1;
|
2003-03-12 22:31:44 +00:00
|
|
|
}
|
2020-03-04 12:09:36 +00:00
|
|
|
}
|
2003-03-12 22:31:44 +00:00
|
|
|
source_paths[i] = 0;
|
|
|
|
}
|
|
|
|
|
2020-02-23 14:29:58 +00:00
|
|
|
#define RUP(x,a) (((x) + ((a) - 1)) & ~((a) - 1))
|
2020-02-24 02:28:43 +00:00
|
|
|
static pr_short_t __attribute__((pure))
|
|
|
|
pr_debug_type_size (const progs_t *pr, const qfot_type_t *type)
|
2007-05-08 02:04:47 +00:00
|
|
|
{
|
2020-02-23 14:29:58 +00:00
|
|
|
pr_short_t size;
|
|
|
|
qfot_type_t *aux_type;
|
|
|
|
switch (type->meta) {
|
|
|
|
case ty_basic:
|
2020-03-30 02:10:05 +00:00
|
|
|
return pr_type_size[type->type];
|
2020-02-23 14:29:58 +00:00
|
|
|
case ty_struct:
|
|
|
|
case ty_union:
|
|
|
|
size = 0;
|
2020-03-30 02:10:05 +00:00
|
|
|
for (pr_int_t i = 0; i < type->strct.num_fields; i++) {
|
|
|
|
const qfot_var_t *field = &type->strct.fields[i];
|
2020-02-23 14:29:58 +00:00
|
|
|
aux_type = &G_STRUCT (pr, qfot_type_t, field->type);
|
|
|
|
size = max (size,
|
|
|
|
field->offset + pr_debug_type_size (pr, aux_type));
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
case ty_enum:
|
2022-01-18 04:21:06 +00:00
|
|
|
return pr_type_size[ev_int];
|
2020-02-23 14:29:58 +00:00
|
|
|
case ty_array:
|
2020-03-30 02:10:05 +00:00
|
|
|
aux_type = &G_STRUCT (pr, qfot_type_t, type->array.type);
|
2020-02-23 14:29:58 +00:00
|
|
|
size = pr_debug_type_size (pr, aux_type);
|
2020-03-30 02:10:05 +00:00
|
|
|
return type->array.size * size;
|
2020-02-23 14:29:58 +00:00
|
|
|
case ty_class:
|
|
|
|
return 1; //FIXME or should it return sizeof class struct?
|
2020-03-27 03:27:46 +00:00
|
|
|
case ty_alias:
|
2020-03-30 02:10:05 +00:00
|
|
|
aux_type = &G_STRUCT (pr, qfot_type_t, type->alias.aux_type);
|
2020-03-27 03:27:46 +00:00
|
|
|
return pr_debug_type_size (pr, aux_type);
|
2020-02-23 14:29:58 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static qfot_type_t *
|
|
|
|
get_def_type (progs_t *pr, pr_def_t *def, qfot_type_t *type)
|
|
|
|
{
|
|
|
|
if (!def->type_encoding) {
|
|
|
|
// no type encoding, so use basic type data to fill in and return
|
|
|
|
// the dummy encoding
|
|
|
|
memset (type, 0, sizeof (*type));
|
2020-03-30 02:10:05 +00:00
|
|
|
type->type = def->type;
|
2020-02-23 14:29:58 +00:00
|
|
|
} else {
|
|
|
|
type = &G_STRUCT (pr, qfot_type_t, def->type_encoding);
|
|
|
|
if (!def->size) {
|
|
|
|
def->size = pr_debug_type_size (pr, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
2007-05-08 02:04:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 13:33:44 +00:00
|
|
|
static pr_def_t
|
2010-11-13 05:36:33 +00:00
|
|
|
parse_expression (progs_t *pr, const char *expr, int conditional)
|
2007-05-08 02:04:47 +00:00
|
|
|
{
|
2007-09-15 07:47:31 +00:00
|
|
|
script_t *es;
|
2007-05-08 02:04:47 +00:00
|
|
|
char *e;
|
2007-09-15 07:47:31 +00:00
|
|
|
pr_type_t *expr_ptr;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t d;
|
2007-09-15 07:47:31 +00:00
|
|
|
|
2011-09-06 14:48:31 +00:00
|
|
|
d.ofs = 0;
|
|
|
|
d.type = ev_invalid;
|
2020-02-22 13:33:44 +00:00
|
|
|
d.name = 0;
|
2007-09-15 07:47:31 +00:00
|
|
|
es = Script_New ();
|
|
|
|
Script_Start (es, "<console>", expr);
|
|
|
|
expr_ptr = 0;
|
2011-09-06 14:48:31 +00:00
|
|
|
es->single = "{}()':[].";
|
2007-09-15 07:47:31 +00:00
|
|
|
if (Script_GetToken (es, 1)) {
|
|
|
|
if (strequal (es->token->str, "[")) {
|
2007-05-08 02:04:47 +00:00
|
|
|
edict_t *ent;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *field;
|
2007-05-08 02:04:47 +00:00
|
|
|
|
2007-09-15 07:47:31 +00:00
|
|
|
if (!Script_GetToken (es, 1))
|
2007-05-08 02:04:47 +00:00
|
|
|
goto error;
|
2007-09-15 07:47:31 +00:00
|
|
|
ent = EDICT_NUM (pr, strtol (es->token->str, &e, 0));
|
|
|
|
if (e == es->token->str)
|
2007-05-08 02:04:47 +00:00
|
|
|
goto error;
|
2007-09-15 07:47:31 +00:00
|
|
|
if (!Script_GetToken (es, 1) && !strequal (es->token->str, "]" ))
|
2007-05-08 02:04:47 +00:00
|
|
|
goto error;
|
2007-09-15 07:47:31 +00:00
|
|
|
if (!Script_GetToken (es, 1) && !strequal (es->token->str, "." ))
|
2007-05-08 02:04:47 +00:00
|
|
|
goto error;
|
2007-09-15 07:47:31 +00:00
|
|
|
if (!Script_GetToken (es, 1))
|
2007-05-08 02:04:47 +00:00
|
|
|
goto error;
|
2007-09-15 07:47:31 +00:00
|
|
|
field = PR_FindField (pr, es->token->str);
|
2007-05-08 02:04:47 +00:00
|
|
|
if (!field)
|
|
|
|
goto error;
|
2011-09-06 14:48:31 +00:00
|
|
|
d = *field;
|
2013-01-17 05:11:54 +00:00
|
|
|
expr_ptr = &E_fld (ent, field->ofs);
|
2011-09-06 14:48:31 +00:00
|
|
|
d.ofs = PR_SetPointer (pr, expr_ptr);
|
2012-08-18 03:20:08 +00:00
|
|
|
} else if (isdigit ((byte) es->token->str[0])) {
|
2007-09-15 07:47:31 +00:00
|
|
|
expr_ptr = PR_GetPointer (pr, strtol (es->token->str, 0, 0));
|
2011-09-06 14:48:31 +00:00
|
|
|
d.type = ev_void;
|
|
|
|
d.ofs = PR_SetPointer (pr, expr_ptr);
|
2007-05-08 02:04:47 +00:00
|
|
|
} else {
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *global = PR_FindGlobal (pr, es->token->str);
|
2007-05-08 02:04:47 +00:00
|
|
|
if (!global)
|
|
|
|
goto error;
|
2011-09-06 14:48:31 +00:00
|
|
|
d = *global;
|
2007-05-08 02:04:47 +00:00
|
|
|
}
|
2010-11-13 05:36:33 +00:00
|
|
|
if (conditional) {
|
2011-09-06 14:48:31 +00:00
|
|
|
es->single = "{}()':[]";
|
2010-11-13 05:36:33 +00:00
|
|
|
pr->wp_conditional = 0;
|
|
|
|
if (Script_TokenAvailable (es, 1)) {
|
|
|
|
if (!Script_GetToken (es, 1)
|
|
|
|
&& !strequal (es->token->str, "==" ))
|
|
|
|
goto error;
|
|
|
|
if (!Script_GetToken (es, 1))
|
|
|
|
goto error;
|
2022-04-26 06:10:00 +00:00
|
|
|
PR_PTR (int, &pr->wp_val) = strtol (es->token->str, &e, 0);
|
2010-11-13 05:36:33 +00:00
|
|
|
if (e == es->token->str)
|
|
|
|
goto error;
|
|
|
|
if (*e == '.' || *e == 'e' || *e == 'E')
|
2022-04-26 06:10:00 +00:00
|
|
|
PR_PTR (float, &pr->wp_val) = strtod (es->token->str, &e);
|
2010-11-13 05:36:33 +00:00
|
|
|
pr->wp_conditional = 1;
|
|
|
|
}
|
2007-05-08 02:25:01 +00:00
|
|
|
}
|
2007-09-15 07:47:31 +00:00
|
|
|
if (Script_TokenAvailable (es, 1))
|
2007-05-08 02:25:01 +00:00
|
|
|
Sys_Printf ("ignoring tail\n");
|
2007-05-08 02:04:47 +00:00
|
|
|
}
|
|
|
|
error:
|
2020-02-26 00:39:03 +00:00
|
|
|
if (es->error) {
|
2021-03-29 08:27:06 +00:00
|
|
|
Sys_Printf ("%s\n", es->error);
|
2020-02-26 00:39:03 +00:00
|
|
|
}
|
2011-09-06 14:48:31 +00:00
|
|
|
Script_Delete (es);
|
|
|
|
return d;
|
2007-05-08 02:04:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void
|
|
|
|
pr_debug_clear (progs_t *pr, void *data)
|
2001-10-08 03:46:44 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
__auto_type res = (prdeb_resources_t *) data;
|
2020-02-23 09:56:30 +00:00
|
|
|
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_clearstr (res->string);
|
|
|
|
dstring_clearstr (res->dva);
|
|
|
|
dstring_clearstr (res->line);
|
|
|
|
dstring_clearstr (res->dstr);
|
2001-10-08 03:46:44 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
if (res->debug)
|
|
|
|
pr->free_progs_mem (pr, res->debug);
|
2020-04-04 03:50:25 +00:00
|
|
|
Hash_FlushTable (res->file_hash);
|
|
|
|
Hash_FlushTable (res->debug_syms);
|
|
|
|
Hash_FlushTable (res->compunits);
|
2021-03-21 12:26:36 +00:00
|
|
|
PR_RESRESET (res->compmap);
|
2020-02-25 11:07:29 +00:00
|
|
|
res->debug = 0;
|
|
|
|
res->auxfunctions = 0;
|
|
|
|
if (res->auxfunction_map)
|
|
|
|
pr->free_progs_mem (pr, res->auxfunction_map);
|
|
|
|
res->auxfunction_map = 0;
|
2021-06-08 07:54:04 +00:00
|
|
|
if (res->sorted_functions)
|
|
|
|
pr->free_progs_mem (pr, res->sorted_functions);
|
|
|
|
res->sorted_functions = 0;
|
2020-02-25 11:07:29 +00:00
|
|
|
res->linenos = 0;
|
|
|
|
res->local_defs = 0;
|
|
|
|
|
|
|
|
pr->watch = 0;
|
|
|
|
pr->wp_conditional = 0;
|
2022-04-26 06:10:00 +00:00
|
|
|
PR_PTR (int, &pr->wp_val) = 0;
|
2001-10-08 03:46:44 +00:00
|
|
|
|
2020-03-14 11:44:43 +00:00
|
|
|
for (int i = 0; i < ev_type_count; i++ ) {
|
|
|
|
res->type_encodings[i] = &res->void_type;
|
|
|
|
}
|
2001-10-08 03:46:44 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static file_t *
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Load_Source_File (progs_t *pr, const char *fname)
|
|
|
|
{
|
2020-02-26 10:30:10 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2010-11-24 02:41:08 +00:00
|
|
|
char *l, *p, **dir;
|
2020-04-03 13:39:27 +00:00
|
|
|
file_t *f = Hash_Find (res->file_hash, fname);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
if (f)
|
|
|
|
return f;
|
2003-03-12 22:31:44 +00:00
|
|
|
f = calloc (1, sizeof (file_t));
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!f)
|
|
|
|
return 0;
|
2003-03-12 22:31:44 +00:00
|
|
|
for (dir = source_paths; *dir && !f->text; dir++) {
|
2020-02-26 10:30:10 +00:00
|
|
|
f->text = pr->load_file (pr, dsprintf (res->dva, "%s%s%s", *dir,
|
|
|
|
**dir ? "/" : "", fname),
|
2020-02-21 12:17:28 +00:00
|
|
|
&f->size);
|
2003-03-12 22:31:44 +00:00
|
|
|
}
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!f->text) {
|
2010-11-24 02:41:08 +00:00
|
|
|
pr->file_error (pr, fname);
|
|
|
|
} else {
|
|
|
|
for (f->num_lines = 1, l = f->text; *l; l++)
|
|
|
|
if (*l == '\n')
|
|
|
|
f->num_lines++;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
f->name = strdup (fname);
|
|
|
|
if (!f->name) {
|
2002-06-11 17:24:37 +00:00
|
|
|
pr->free_progs_mem (pr, f->text);
|
2001-07-14 23:53:59 +00:00
|
|
|
free (f);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-11-24 02:41:08 +00:00
|
|
|
if (f->num_lines) {
|
|
|
|
f->lines = malloc (f->num_lines * sizeof (line_t));
|
|
|
|
if (!f->lines) {
|
|
|
|
free (f->name);
|
|
|
|
pr->free_progs_mem (pr, f->text);
|
|
|
|
free (f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
f->lines[0].text = f->text;
|
|
|
|
for (f->num_lines = 0, l = f->text; *l; l++) {
|
|
|
|
if (*l == '\n') {
|
2012-08-18 03:20:08 +00:00
|
|
|
for (p = l; p > f->lines[f->num_lines].text
|
|
|
|
&& isspace((byte) p[-1]); p--)
|
2010-11-24 02:41:08 +00:00
|
|
|
;
|
|
|
|
f->lines[f->num_lines].len = p - f->lines[f->num_lines].text;
|
|
|
|
f->lines[++f->num_lines].text = l + 1;
|
|
|
|
}
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2010-11-24 02:41:08 +00:00
|
|
|
f->lines[f->num_lines].len = l - f->lines[f->num_lines].text;
|
|
|
|
f->num_lines++;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2002-06-11 17:24:37 +00:00
|
|
|
f->pr = pr;
|
2020-04-03 13:39:27 +00:00
|
|
|
Hash_Add (res->file_hash, f);
|
2001-07-14 23:53:59 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2020-04-04 03:50:25 +00:00
|
|
|
static void
|
|
|
|
byteswap_def (pr_def_t *def)
|
|
|
|
{
|
|
|
|
def->type = LittleShort (def->type);
|
|
|
|
def->size = LittleShort (def->size);
|
|
|
|
def->ofs = LittleLong (def->ofs);
|
|
|
|
def->name = LittleLong (def->name);
|
|
|
|
def->type_encoding = LittleLong (def->type_encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
static compunit_t *
|
|
|
|
new_compunit (prdeb_resources_t *res)
|
|
|
|
{
|
2021-03-21 12:26:36 +00:00
|
|
|
return PR_RESNEW (res->compmap);
|
2020-04-04 03:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_compunit (prdeb_resources_t *res, pr_def_t *def)
|
|
|
|
{
|
|
|
|
progs_t *pr = res->pr;
|
|
|
|
__auto_type compunit = (pr_compunit_t *) (res->debug_data + def->ofs);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < compunit->num_files; i++) {
|
|
|
|
compunit_t *cu = new_compunit (res);
|
|
|
|
cu->unit = compunit;
|
|
|
|
cu->file = PR_GetString (pr, compunit->files[i]);
|
|
|
|
Hash_Add (res->compunits, cu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 01:06:01 +00:00
|
|
|
static int
|
|
|
|
def_compare_sort (const void *_da, const void *_db, void *_res)
|
|
|
|
{
|
|
|
|
pr_def_t da = *(const pr_def_t *)_da;
|
|
|
|
pr_def_t db = *(const pr_def_t *)_db;
|
|
|
|
return da.ofs - db.ofs;
|
|
|
|
}
|
|
|
|
|
2021-06-08 07:54:04 +00:00
|
|
|
static int
|
|
|
|
func_compare_sort (const void *_fa, const void *_fb, void *_res)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = _res;
|
|
|
|
progs_t *pr = res->pr;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t fa = *(const pr_func_t *)_fa;
|
|
|
|
pr_func_t fb = *(const pr_func_t *)_fb;
|
2021-12-31 06:02:31 +00:00
|
|
|
const char *fa_file = PR_GetString (pr, pr->pr_functions[fa].file);
|
|
|
|
const char *fb_file = PR_GetString (pr, pr->pr_functions[fb].file);
|
2021-06-08 07:54:04 +00:00
|
|
|
int cmp = strcmp (fa_file, fb_file);
|
|
|
|
if (cmp) {
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
pr_auxfunction_t *fa_aux = res->auxfunction_map[fa];
|
|
|
|
pr_auxfunction_t *fb_aux = res->auxfunction_map[fb];
|
|
|
|
pr_uint_t fa_line = fa_aux ? fa_aux->source_line : 0;
|
|
|
|
pr_uint_t fb_line = fb_aux ? fb_aux->source_line : 0;
|
|
|
|
return fa_line - fb_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
func_compare_search (const void *_key, const void *_f, void *_res)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = _res;
|
|
|
|
progs_t *pr = res->pr;
|
|
|
|
const func_key_t *key = _key;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t f = *(const pr_func_t *)_f;
|
2021-12-31 06:02:31 +00:00
|
|
|
const char *f_file = PR_GetString (pr, pr->pr_functions[f].file);
|
2021-06-08 07:54:04 +00:00
|
|
|
int cmp = strcmp (key->file, f_file);
|
|
|
|
if (cmp) {
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
pr_auxfunction_t *f_aux = res->auxfunction_map[f];
|
|
|
|
pr_uint_t f_line = f_aux ? f_aux->source_line : 0;
|
|
|
|
return key->line - f_line;
|
|
|
|
}
|
|
|
|
|
2021-12-26 13:39:37 +00:00
|
|
|
VISIBLE void
|
|
|
|
PR_DebugSetSym (progs_t *pr, pr_debug_header_t *debug)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
|
|
|
|
res->auxfunctions = (pr_auxfunction_t*)((char*)debug + debug->auxfunctions);
|
|
|
|
res->linenos = (pr_lineno_t*)((char*)debug + debug->linenos);
|
|
|
|
res->local_defs = (pr_def_t*)((char*)debug + debug->locals);
|
|
|
|
res->debug_defs = (pr_def_t*)((char*)debug + debug->debug_defs);
|
|
|
|
res->debug_data = (pr_type_t*)((char*)debug + debug->debug_data);
|
|
|
|
|
|
|
|
size_t size;
|
2022-01-26 10:30:25 +00:00
|
|
|
size = pr->progs->functions.count * sizeof (pr_auxfunction_t *);
|
2021-12-26 13:39:37 +00:00
|
|
|
res->auxfunction_map = pr->allocate_progs_mem (pr, size);
|
2022-01-26 10:30:25 +00:00
|
|
|
size = pr->progs->functions.count * sizeof (pr_func_t);
|
2021-12-26 13:39:37 +00:00
|
|
|
res->sorted_functions = pr->allocate_progs_mem (pr, size);
|
|
|
|
|
2022-01-26 10:30:25 +00:00
|
|
|
for (pr_uint_t i = 0; i < pr->progs->functions.count; i++) {
|
2021-12-26 13:39:37 +00:00
|
|
|
res->auxfunction_map[i] = 0;
|
|
|
|
res->sorted_functions[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
qfot_type_encodings_t *encodings = 0;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t type_encodings = 0;
|
2021-12-26 13:39:37 +00:00
|
|
|
res->type_encodings_def = PR_FindGlobal (pr, ".type_encodings");
|
|
|
|
if (res->type_encodings_def) {
|
|
|
|
encodings = &G_STRUCT (pr, qfot_type_encodings_t,
|
|
|
|
res->type_encodings_def->ofs);
|
|
|
|
type_encodings = encodings->types;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pr_uint_t i = 0; i < debug->num_auxfunctions; i++) {
|
|
|
|
if (type_encodings) {
|
|
|
|
res->auxfunctions[i].return_type += type_encodings;
|
|
|
|
}
|
|
|
|
res->auxfunction_map[res->auxfunctions[i].function] =
|
|
|
|
&res->auxfunctions[i];
|
2022-04-30 01:06:01 +00:00
|
|
|
heapsort_r (res->local_defs + res->auxfunctions[i].local_defs,
|
|
|
|
res->auxfunctions[i].num_locals, sizeof (pr_def_t),
|
|
|
|
def_compare_sort, res);
|
2021-12-26 13:39:37 +00:00
|
|
|
}
|
2022-04-30 01:06:01 +00:00
|
|
|
heapsort_r (res->sorted_functions, pr->progs->functions.count,
|
|
|
|
sizeof (pr_func_t), func_compare_sort, res);
|
2021-12-26 13:39:37 +00:00
|
|
|
|
|
|
|
for (pr_uint_t i = 0; i < debug->num_locals; i++) {
|
|
|
|
if (type_encodings) {
|
|
|
|
res->local_defs[i].type_encoding += type_encodings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t compunit_str = PR_FindString (pr, ".compile_unit");
|
2021-12-26 13:39:37 +00:00
|
|
|
for (pr_uint_t i = 0; i < debug->num_debug_defs; i++) {
|
|
|
|
pr_def_t *def = &res->debug_defs[i];
|
|
|
|
if (type_encodings) {
|
|
|
|
def->type_encoding += type_encodings;
|
|
|
|
}
|
|
|
|
Hash_Add (res->debug_syms, def);
|
|
|
|
if (def->name == compunit_str) {
|
|
|
|
process_compunit (res, def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encodings) {
|
|
|
|
qfot_type_t *type;
|
2022-01-18 03:11:14 +00:00
|
|
|
for (pr_ptr_t type_ptr = 4; type_ptr < encodings->size;
|
2021-12-26 13:39:37 +00:00
|
|
|
type_ptr += type->size) {
|
|
|
|
type = &G_STRUCT (pr, qfot_type_t, type_encodings + type_ptr);
|
|
|
|
if (type->meta == ty_basic
|
2022-03-30 15:16:29 +00:00
|
|
|
&& (unsigned) type->type < ev_type_count) {
|
2021-12-26 13:39:37 +00:00
|
|
|
res->type_encodings[type->type] = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res->debug = debug;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_LoadDebug (progs_t *pr)
|
|
|
|
{
|
2021-12-26 11:35:09 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-04 12:30:49 +00:00
|
|
|
char *sym_path;
|
|
|
|
const char *path_end, *sym_file;
|
2020-02-21 12:17:28 +00:00
|
|
|
off_t debug_size;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t i;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def;
|
2001-07-15 02:05:29 +00:00
|
|
|
pr_type_t *str = 0;
|
2021-12-26 13:39:37 +00:00
|
|
|
pr_debug_header_t *debug;
|
|
|
|
|
|
|
|
res->debug = 0;
|
2001-07-15 02:05:29 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (!pr_debug)
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-19 07:27:14 +00:00
|
|
|
|
2001-07-15 02:05:29 +00:00
|
|
|
def = PR_FindGlobal (pr, ".debug_file");
|
|
|
|
if (def)
|
|
|
|
str = &pr->pr_globals[def->ofs];
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
if (!str)
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2022-04-26 06:10:00 +00:00
|
|
|
res->debugfile = PR_GetString (pr, PR_PTR (string, str));
|
2020-02-25 11:07:29 +00:00
|
|
|
sym_file = QFS_SkipPath (res->debugfile);
|
2003-02-14 19:46:07 +00:00
|
|
|
path_end = QFS_SkipPath (pr->progs_name);
|
2004-11-02 04:59:00 +00:00
|
|
|
sym_path = malloc (strlen (sym_file) + (path_end - pr->progs_name) + 1);
|
2001-07-14 23:53:59 +00:00
|
|
|
strncpy (sym_path, pr->progs_name, path_end - pr->progs_name);
|
|
|
|
strcpy (sym_path + (path_end - pr->progs_name), sym_file);
|
2021-12-26 13:39:37 +00:00
|
|
|
debug = pr->load_file (pr, sym_path, &debug_size);
|
|
|
|
if (!debug) {
|
2001-07-14 23:53:59 +00:00
|
|
|
Sys_Printf ("can't load %s for debug info\n", sym_path);
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2021-12-26 13:39:37 +00:00
|
|
|
debug->version = LittleLong (debug->version);
|
|
|
|
if (debug->version != PROG_DEBUG_VERSION) {
|
2001-07-14 23:53:59 +00:00
|
|
|
Sys_Printf ("ignoring %s with unsupported version %x.%03x.%03x\n",
|
|
|
|
sym_path,
|
2021-12-26 13:39:37 +00:00
|
|
|
(debug->version >> 24) & 0xff,
|
|
|
|
(debug->version >> 12) & 0xfff,
|
|
|
|
debug->version & 0xfff);
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2021-12-26 13:39:37 +00:00
|
|
|
debug->crc = LittleShort (debug->crc);
|
|
|
|
if (debug->crc != pr->crc) {
|
2001-09-10 12:56:23 +00:00
|
|
|
Sys_Printf ("ignoring %s that doesn't match %s. (CRCs: "
|
|
|
|
"sym:%d dat:%d)\n",
|
2021-12-26 13:39:37 +00:00
|
|
|
sym_path, pr->progs_name, debug->crc, pr->crc);
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2004-11-02 04:59:00 +00:00
|
|
|
free (sym_path);
|
2021-12-26 13:39:37 +00:00
|
|
|
debug->you_tell_me_and_we_will_both_know = LittleShort
|
|
|
|
(debug->you_tell_me_and_we_will_both_know);
|
|
|
|
debug->auxfunctions = LittleLong (debug->auxfunctions);
|
|
|
|
debug->num_auxfunctions = LittleLong (debug->num_auxfunctions);
|
|
|
|
debug->linenos = LittleLong (debug->linenos);
|
|
|
|
debug->num_linenos = LittleLong (debug->num_linenos);
|
|
|
|
debug->locals = LittleLong (debug->locals);
|
|
|
|
debug->num_locals = LittleLong (debug->num_locals);
|
|
|
|
debug->debug_defs = LittleLong (debug->debug_defs);
|
|
|
|
debug->num_debug_defs = LittleLong (debug->num_debug_defs);
|
|
|
|
debug->debug_data = LittleLong (debug->debug_data);
|
|
|
|
debug->debug_data_size = LittleLong (debug->debug_data_size);
|
|
|
|
|
|
|
|
__auto_type auxfuncs = (pr_auxfunction_t*)((char*)debug
|
|
|
|
+ debug->auxfunctions);
|
|
|
|
for (i = 0; i < debug->num_auxfunctions; i++) {
|
|
|
|
auxfuncs[i].function = LittleLong (auxfuncs[i].function);
|
|
|
|
auxfuncs[i].source_line = LittleLong (auxfuncs[i].source_line);
|
|
|
|
auxfuncs[i].line_info = LittleLong (auxfuncs[i].line_info);
|
|
|
|
auxfuncs[i].local_defs = LittleLong (auxfuncs[i].local_defs);
|
|
|
|
auxfuncs[i].num_locals = LittleLong (auxfuncs[i].num_locals);
|
2021-06-08 07:54:04 +00:00
|
|
|
}
|
2020-02-25 11:07:29 +00:00
|
|
|
|
2021-12-26 13:39:37 +00:00
|
|
|
__auto_type linenos = (pr_lineno_t*)((char*)debug + debug->linenos);
|
|
|
|
for (i = 0; i < debug->num_linenos; i++) {
|
|
|
|
linenos[i].fa.func = LittleLong (linenos[i].fa.func);
|
|
|
|
linenos[i].line = LittleLong (linenos[i].line);
|
2020-03-14 14:38:22 +00:00
|
|
|
}
|
2020-02-25 11:07:29 +00:00
|
|
|
|
2021-12-26 13:39:37 +00:00
|
|
|
__auto_type local_defs = (pr_def_t*)((char*)debug + debug->locals);
|
|
|
|
for (i = 0; i < debug->num_locals; i++) {
|
|
|
|
byteswap_def (&local_defs[i]);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2021-12-26 13:39:37 +00:00
|
|
|
__auto_type debug_defs = (pr_def_t*)((char*)debug + debug->locals);
|
|
|
|
for (i = 0; i < debug->num_debug_defs; i++) {
|
|
|
|
byteswap_def (&debug_defs[i]);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2021-12-26 13:39:37 +00:00
|
|
|
|
|
|
|
PR_DebugSetSym (pr, debug);
|
2003-11-20 07:46:56 +00:00
|
|
|
return 1;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 03:50:25 +00:00
|
|
|
VISIBLE const char *
|
|
|
|
PR_Debug_GetBaseDirectory (progs_t *pr, const char *file)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
__auto_type cu = (compunit_t *) Hash_Find (res->compunits, file);
|
|
|
|
|
|
|
|
if (cu) {
|
|
|
|
return PR_GetString (pr, cu->unit->basedir);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
VISIBLE pr_auxfunction_t *
|
|
|
|
PR_Debug_AuxFunction (progs_t *pr, pr_uint_t func)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
if (!res->debug || func >= res->debug->num_auxfunctions) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return &res->auxfunctions[func];
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE pr_auxfunction_t *
|
|
|
|
PR_Debug_MappedAuxFunction (progs_t *pr, pr_uint_t func)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2022-01-26 10:30:25 +00:00
|
|
|
if (!res->debug || func >= pr->progs->functions.count) {
|
2020-02-25 11:07:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return res->auxfunction_map[func];
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE pr_def_t *
|
|
|
|
PR_Debug_LocalDefs (progs_t *pr, pr_auxfunction_t *aux_function)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
if (!res->debug || !aux_function) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (aux_function->local_defs > res->debug->num_locals) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return res->local_defs + aux_function->local_defs;
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE pr_lineno_t *
|
|
|
|
PR_Debug_Linenos (progs_t *pr, pr_auxfunction_t *aux_function,
|
|
|
|
pr_uint_t *num_linenos)
|
|
|
|
{
|
|
|
|
pr_uint_t i, count;
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
if (!res->debug) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!aux_function) {
|
|
|
|
*num_linenos = res->debug->num_linenos;
|
|
|
|
return res->linenos;
|
|
|
|
}
|
|
|
|
if (aux_function->line_info > res->debug->num_linenos) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//FIXME put lineno count in sym file
|
|
|
|
for (count = 1, i = aux_function->line_info + 1;
|
|
|
|
i < res->debug->num_linenos; i++, count++) {
|
|
|
|
if (!res->linenos[i].line) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*num_linenos = count;
|
|
|
|
return res->linenos + aux_function->line_info;
|
|
|
|
}
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
pr_auxfunction_t *
|
|
|
|
PR_Get_Lineno_Func (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
while (lineno > res->linenos && lineno->line)
|
2001-07-14 23:53:59 +00:00
|
|
|
lineno--;
|
|
|
|
if (lineno->line)
|
|
|
|
return 0;
|
2020-02-25 11:07:29 +00:00
|
|
|
return &res->auxfunctions[lineno->fa.func];
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2001-07-14 23:53:59 +00:00
|
|
|
pr_auxfunction_t *f;
|
|
|
|
|
|
|
|
if (lineno->line)
|
|
|
|
return lineno->fa.addr;
|
2020-02-25 11:07:29 +00:00
|
|
|
if (lineno->fa.func < res->debug->num_auxfunctions) {
|
|
|
|
f = &res->auxfunctions[lineno->fa.func];
|
2011-02-14 02:27:05 +00:00
|
|
|
return pr->pr_functions[f->function].first_statement;
|
|
|
|
}
|
|
|
|
// take a wild guess that only the line number is bogus and return
|
|
|
|
// the address anyway
|
|
|
|
return lineno->fa.addr;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
if (lineno->line)
|
|
|
|
return lineno->line;
|
2004-02-10 04:42:17 +00:00
|
|
|
return 0;
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pr_lineno_t *
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_Find_Lineno (progs_t *pr, pr_uint_t addr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t i;
|
|
|
|
pr_lineno_t *lineno = 0;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
if (!res->debug)
|
2001-07-14 23:53:59 +00:00
|
|
|
return 0;
|
2020-02-25 11:07:29 +00:00
|
|
|
if (!res->debug->num_linenos)
|
2001-07-14 23:53:59 +00:00
|
|
|
return 0;
|
2020-02-25 11:07:29 +00:00
|
|
|
for (i = res->debug->num_linenos; i > 0; i--) {
|
|
|
|
if (PR_Get_Lineno_Addr (pr, &res->linenos[i - 1]) <= addr) {
|
|
|
|
lineno = &res->linenos[i - 1];
|
2001-07-14 23:53:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
2021-06-08 07:54:04 +00:00
|
|
|
pr_uint_t
|
|
|
|
PR_FindSourceLineAddr (progs_t *pr, const char *file, pr_uint_t line)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
func_key_t key = { file, line };
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t *f = fbsearch_r (&key, res->sorted_functions,
|
2022-01-26 10:30:25 +00:00
|
|
|
pr->progs->functions.count, sizeof (pr_func_t),
|
2021-06-08 07:54:04 +00:00
|
|
|
func_compare_search, res);
|
|
|
|
if (!f) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dfunction_t *func = &pr->pr_functions[*f];
|
|
|
|
if (func->first_statement <= 0
|
2021-12-31 06:02:31 +00:00
|
|
|
|| strcmp (file, PR_GetString (pr, func->file)) != 0) {
|
2021-06-08 07:54:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pr_auxfunction_t *aux = res->auxfunction_map[*f];
|
|
|
|
if (!aux) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pr_uint_t addr = func->first_statement;
|
|
|
|
line -= aux->source_line;
|
|
|
|
|
|
|
|
//FIXME put lineno count in sym file
|
|
|
|
for (pr_uint_t i = aux->line_info + 1; i < res->debug->num_linenos; i++) {
|
|
|
|
if (!res->linenos[i].line) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res->linenos[i].line <= line) {
|
|
|
|
addr = res->linenos[i].fa.addr;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
const char *
|
|
|
|
PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno)
|
|
|
|
{
|
|
|
|
pr_auxfunction_t *f;
|
|
|
|
|
|
|
|
f = PR_Get_Lineno_Func (pr, lineno);
|
2022-01-26 10:30:25 +00:00
|
|
|
if (f->function >= (unsigned) pr->progs->functions.count)
|
2011-02-14 02:27:05 +00:00
|
|
|
return 0;
|
2021-12-31 06:02:31 +00:00
|
|
|
return PR_GetString(pr, pr->pr_functions[f->function].file);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_Get_Source_Line (progs_t *pr, pr_uint_t addr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2020-02-26 10:30:10 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-04 12:30:49 +00:00
|
|
|
const char *fname;
|
|
|
|
pr_uint_t line;
|
|
|
|
file_t *file;
|
|
|
|
pr_auxfunction_t *func;
|
|
|
|
pr_lineno_t *lineno;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2003-02-24 03:34:11 +00:00
|
|
|
lineno = PR_Find_Lineno (pr, addr);
|
2001-07-14 23:53:59 +00:00
|
|
|
if (!lineno || PR_Get_Lineno_Addr (pr, lineno) != addr)
|
|
|
|
return 0;
|
|
|
|
func = PR_Get_Lineno_Func (pr, lineno);
|
|
|
|
fname = PR_Get_Source_File (pr, lineno);
|
|
|
|
if (!func || !fname)
|
|
|
|
return 0;
|
|
|
|
line = PR_Get_Lineno_Line (pr, lineno);
|
2004-02-10 04:42:17 +00:00
|
|
|
line += func->source_line;
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2001-07-15 02:57:36 +00:00
|
|
|
file = PR_Load_Source_File (pr, fname);
|
|
|
|
|
2011-02-14 02:27:05 +00:00
|
|
|
if (!file || !file->lines || !line || line > file->num_lines)
|
2020-02-26 10:30:10 +00:00
|
|
|
return dsprintf (res->dva, "%s:%u", fname, line);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2020-02-26 10:30:10 +00:00
|
|
|
return dsprintf (res->dva, "%s:%u:%.*s", fname, line,
|
|
|
|
(int)file->lines[line - 1].len,
|
|
|
|
file->lines[line - 1].text);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *
|
2022-01-27 01:55:06 +00:00
|
|
|
PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned param)
|
2007-04-09 06:16:03 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-09 06:16:03 +00:00
|
|
|
pr_uint_t i;
|
|
|
|
pr_auxfunction_t *aux_func;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *ddef = 0;
|
2011-01-09 11:53:39 +00:00
|
|
|
int num_params;
|
|
|
|
int param_offs = 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
if (!res->debug)
|
2007-05-07 23:10:54 +00:00
|
|
|
return 0;
|
2007-04-09 06:16:03 +00:00
|
|
|
if (!func)
|
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2022-01-27 01:55:06 +00:00
|
|
|
num_params = func->numparams;
|
2011-01-09 11:53:39 +00:00
|
|
|
if (num_params < 0) {
|
|
|
|
num_params = ~num_params; // one's compliment
|
|
|
|
param_offs = 1; // skip over @args def
|
|
|
|
}
|
2022-01-27 01:55:06 +00:00
|
|
|
if (param >= (unsigned) num_params)
|
2007-04-09 06:16:03 +00:00
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
aux_func = res->auxfunction_map[func - pr->pr_functions];
|
2007-04-09 06:16:03 +00:00
|
|
|
if (!aux_func)
|
|
|
|
return 0;
|
2007-04-09 06:18:14 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
for (i = 0; i < aux_func->num_locals; i++) {
|
2020-02-25 11:07:29 +00:00
|
|
|
ddef = &res->local_defs[aux_func->local_defs + param_offs + i];
|
2022-01-27 01:55:06 +00:00
|
|
|
if (!param--)
|
2007-04-09 06:16:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ddef;
|
|
|
|
}
|
|
|
|
|
2007-09-15 07:47:31 +00:00
|
|
|
static pr_auxfunction_t *
|
|
|
|
get_aux_function (progs_t *pr)
|
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-09-15 07:47:31 +00:00
|
|
|
dfunction_t *func;
|
2020-02-25 11:07:29 +00:00
|
|
|
if (!pr->pr_xfunction || !res->auxfunction_map)
|
2007-09-15 07:47:31 +00:00
|
|
|
return 0;
|
|
|
|
func = pr->pr_xfunction->descriptor;
|
2020-02-25 11:07:29 +00:00
|
|
|
return res->auxfunction_map[func - pr->pr_functions];
|
2007-09-15 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-14 11:44:43 +00:00
|
|
|
static qfot_type_t *
|
|
|
|
get_type (prdeb_resources_t *res, int typeptr)
|
2001-07-19 07:27:14 +00:00
|
|
|
{
|
2020-03-14 11:44:43 +00:00
|
|
|
progs_t *pr = res->pr;
|
2019-06-09 09:11:56 +00:00
|
|
|
|
2020-02-25 11:45:36 +00:00
|
|
|
if (!typeptr) {
|
2020-03-14 11:44:43 +00:00
|
|
|
return &res->void_type;
|
2019-06-09 09:11:56 +00:00
|
|
|
}
|
2020-03-14 11:44:43 +00:00
|
|
|
return &G_STRUCT (pr, qfot_type_t, typeptr);
|
2019-06-09 09:11:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *
|
2022-01-18 03:11:14 +00:00
|
|
|
PR_Get_Local_Def (progs_t *pr, pr_ptr_t *offset)
|
2001-07-19 07:27:14 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-07 01:41:23 +00:00
|
|
|
dfunction_t *func;
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_auxfunction_t *aux_func;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t offs = *offset;
|
2020-03-14 17:51:29 +00:00
|
|
|
pr_def_t *def;
|
2001-07-19 07:27:14 +00:00
|
|
|
|
2007-04-07 01:41:23 +00:00
|
|
|
if (!pr->pr_xfunction)
|
2001-07-19 07:27:14 +00:00
|
|
|
return 0;
|
2007-04-07 01:41:23 +00:00
|
|
|
func = pr->pr_xfunction->descriptor;
|
2011-02-15 06:02:31 +00:00
|
|
|
if (!func)
|
|
|
|
return 0;
|
2020-02-25 11:07:29 +00:00
|
|
|
aux_func = res->auxfunction_map[func - pr->pr_functions];
|
2001-07-19 07:27:14 +00:00
|
|
|
if (!aux_func)
|
|
|
|
return 0;
|
2022-01-27 05:16:05 +00:00
|
|
|
|
|
|
|
pr_ptr_t locals_start;
|
|
|
|
if (pr->progs->version == PROG_VERSION) {
|
|
|
|
if (pr->pr_depth) {
|
|
|
|
prstack_t *frame = pr->pr_stack + pr->pr_depth - 1;
|
|
|
|
locals_start = frame->stack_ptr - func->params_start;
|
|
|
|
} else {
|
|
|
|
locals_start = 0; //FIXME ? when disassembling in qfprogs
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
locals_start = func->params_start;
|
|
|
|
}
|
|
|
|
offs -= locals_start;
|
2020-02-22 13:33:44 +00:00
|
|
|
if (offs >= func->locals)
|
2001-07-19 07:27:14 +00:00
|
|
|
return 0;
|
2020-03-14 17:51:29 +00:00
|
|
|
if ((def = PR_SearchDefs (res->local_defs + aux_func->local_defs,
|
|
|
|
aux_func->num_locals, offs))) {
|
|
|
|
*offset = offs - def->ofs;
|
|
|
|
}
|
|
|
|
return def;
|
2001-07-19 07:27:14 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-10-08 03:46:44 +00:00
|
|
|
PR_DumpState (progs_t *pr)
|
2001-07-14 23:53:59 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2003-08-24 05:08:47 +00:00
|
|
|
if (pr->pr_xfunction) {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug && res->debug) {
|
2003-08-24 05:08:47 +00:00
|
|
|
pr_lineno_t *lineno;
|
|
|
|
pr_auxfunction_t *func = 0;
|
2007-04-07 01:41:23 +00:00
|
|
|
dfunction_t *descriptor = pr->pr_xfunction->descriptor;
|
2007-04-06 00:47:41 +00:00
|
|
|
pr_int_t addr = pr->pr_xstatement;
|
2003-08-24 05:08:47 +00:00
|
|
|
|
|
|
|
lineno = PR_Find_Lineno (pr, addr);
|
|
|
|
if (lineno)
|
|
|
|
func = PR_Get_Lineno_Func (pr, lineno);
|
2007-04-07 01:41:23 +00:00
|
|
|
if (func && descriptor == pr->pr_functions + func->function)
|
2003-08-24 05:08:47 +00:00
|
|
|
addr = PR_Get_Lineno_Addr (pr, lineno);
|
|
|
|
else
|
2007-04-07 01:41:23 +00:00
|
|
|
addr = max (descriptor->first_statement, addr - 5);
|
2003-08-24 05:08:47 +00:00
|
|
|
|
|
|
|
while (addr != pr->pr_xstatement)
|
2007-04-09 06:16:03 +00:00
|
|
|
PR_PrintStatement (pr, pr->pr_statements + addr++, 3);
|
2003-08-24 05:08:47 +00:00
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
PR_PrintStatement (pr, pr->pr_statements + pr->pr_xstatement, 3);
|
2001-10-08 03:46:44 +00:00
|
|
|
}
|
|
|
|
PR_StackTrace (pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
|
2010-11-20 05:12:40 +00:00
|
|
|
#define ISDENORM(x) ((x) && !((x) & 0x7f800000))
|
|
|
|
|
2022-01-30 01:47:37 +00:00
|
|
|
static void
|
2020-02-23 09:56:30 +00:00
|
|
|
value_string (pr_debug_data_t *data, qfot_type_t *type, pr_type_t *value)
|
2004-01-31 04:26:01 +00:00
|
|
|
{
|
2020-02-23 09:56:30 +00:00
|
|
|
switch (type->meta) {
|
|
|
|
case ty_basic:
|
2020-03-30 02:10:05 +00:00
|
|
|
switch (type->type) {
|
2022-01-30 01:47:37 +00:00
|
|
|
#define EV_TYPE(t) \
|
|
|
|
case ev_##t: \
|
|
|
|
raw_type_view.t##_view (type, value, data); \
|
2022-01-18 13:08:37 +00:00
|
|
|
break;
|
2022-01-30 01:47:37 +00:00
|
|
|
#include "QF/progs/pr_type_names.h"
|
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
case ev_invalid:
|
|
|
|
case ev_type_count:
|
|
|
|
dstring_appendstr (data->dstr, "<?""?>");
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-02-23 09:56:30 +00:00
|
|
|
case ty_struct:
|
|
|
|
raw_type_view.struct_view (type, value, data);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
2020-02-23 09:56:30 +00:00
|
|
|
case ty_union:
|
|
|
|
raw_type_view.union_view (type, value, data);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
2020-02-23 09:56:30 +00:00
|
|
|
case ty_enum:
|
|
|
|
raw_type_view.enum_view (type, value, data);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
2020-02-23 09:56:30 +00:00
|
|
|
case ty_array:
|
|
|
|
raw_type_view.array_view (type, value, data);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
2020-02-23 09:56:30 +00:00
|
|
|
case ty_class:
|
|
|
|
raw_type_view.class_view (type, value, data);
|
2004-01-31 04:26:01 +00:00
|
|
|
break;
|
2020-03-27 03:27:46 +00:00
|
|
|
case ty_alias://XXX
|
2020-03-30 02:10:05 +00:00
|
|
|
type = &G_STRUCT (data->pr, qfot_type_t, type->alias.aux_type);
|
2022-01-30 01:47:37 +00:00
|
|
|
value_string (data, type, value);
|
|
|
|
break;
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 13:33:44 +00:00
|
|
|
static pr_def_t *
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_debug_find_def (progs_t *pr, pr_ptr_t *ofs)
|
2004-01-31 04:26:01 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def = 0;
|
2004-01-31 04:26:01 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug && res->debug) {
|
2004-01-31 04:26:01 +00:00
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
2020-03-14 17:51:29 +00:00
|
|
|
}
|
2022-01-27 05:16:05 +00:00
|
|
|
if (*ofs >= pr->progs->globals.count) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-14 17:51:29 +00:00
|
|
|
if (!def) {
|
|
|
|
def = PR_GlobalAtOfs (pr, *ofs);
|
|
|
|
if (def) {
|
|
|
|
*ofs -= def->ofs;
|
|
|
|
}
|
|
|
|
}
|
2004-01-31 04:26:01 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2022-01-18 03:11:14 +00:00
|
|
|
global_string (pr_debug_data_t *data, pr_ptr_t offset, qfot_type_t *type,
|
2020-02-23 09:56:30 +00:00
|
|
|
int contents)
|
2004-01-31 04:26:01 +00:00
|
|
|
{
|
2020-02-23 09:56:30 +00:00
|
|
|
progs_t *pr = data->pr;
|
2020-03-14 11:44:43 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_t *dstr = data->dstr;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *def = NULL;
|
2020-02-23 09:56:30 +00:00
|
|
|
qfot_type_t dummy_type = { };
|
|
|
|
const char *name = 0;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t offs = offset;
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_clearstr (dstr);
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-03-30 02:10:05 +00:00
|
|
|
if (type && type->meta == ty_basic && type->type == ev_short) {
|
2020-03-14 17:51:29 +00:00
|
|
|
dsprintf (dstr, "%04x", (short) offset);
|
2020-02-23 09:56:30 +00:00
|
|
|
return dstr->str;
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-14 17:51:29 +00:00
|
|
|
if (offset > pr->globals_size) {
|
|
|
|
dsprintf (dstr, "%08x out of bounds", offset);
|
2020-02-23 09:56:30 +00:00
|
|
|
return dstr->str;
|
|
|
|
}
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-03-14 17:51:29 +00:00
|
|
|
def = pr_debug_find_def (pr, &offs);
|
2020-02-23 09:56:30 +00:00
|
|
|
if (!def || !PR_StringValid (pr, def->name)
|
|
|
|
|| !*(name = PR_GetString (pr, def->name))) {
|
2020-03-14 17:51:29 +00:00
|
|
|
dsprintf (dstr, "[$%x]", offset);
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
if (name) {
|
|
|
|
if (strequal (name, "IMMEDIATE") || strequal (name, ".imm")) {
|
|
|
|
contents = 1;
|
|
|
|
} else {
|
2020-03-14 17:51:29 +00:00
|
|
|
if (offs) {
|
|
|
|
dsprintf (dstr, "{%s + %u}", name, offs);
|
|
|
|
} else {
|
|
|
|
dsprintf (dstr, "%s", name);
|
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (contents) {
|
|
|
|
if (name) {
|
|
|
|
dstring_appendstr (dstr, "(");
|
|
|
|
}
|
2020-03-14 11:44:43 +00:00
|
|
|
if (!type) {
|
|
|
|
if (def) {
|
|
|
|
if (!def->type_encoding) {
|
2020-03-30 02:10:05 +00:00
|
|
|
dummy_type.type = def->type;
|
2020-03-14 11:44:43 +00:00
|
|
|
type = &dummy_type;
|
|
|
|
} else {
|
|
|
|
type = &G_STRUCT (pr, qfot_type_t, def->type_encoding);
|
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
} else {
|
2020-03-14 11:44:43 +00:00
|
|
|
type = &res->void_type;
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-14 17:51:29 +00:00
|
|
|
value_string (data, type, pr->pr_globals + offset);
|
2020-02-23 09:56:30 +00:00
|
|
|
if (name) {
|
|
|
|
dstring_appendstr (dstr, ")");
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
return dstr->str;
|
|
|
|
}
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void
|
|
|
|
pr_debug_void_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dasprintf (data->dstr, "<void>");
|
|
|
|
}
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void
|
|
|
|
pr_debug_string_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
2022-04-26 06:10:00 +00:00
|
|
|
pr_string_t string = PR_PTR (string, value);
|
2020-02-23 09:56:30 +00:00
|
|
|
if (PR_StringValid (data->pr, string)) {
|
|
|
|
const char *str = PR_GetString (data->pr, string);
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_appendstr (dstr, "\"");
|
|
|
|
while (*str) {
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
for (s = str; *s && !strchr ("\"\n\t", *s); s++) {
|
|
|
|
}
|
|
|
|
if (s != str) {
|
|
|
|
dstring_appendsubstr (dstr, str, s - str);
|
|
|
|
}
|
|
|
|
if (*s) {
|
|
|
|
switch (*s) {
|
|
|
|
case '\"':
|
|
|
|
dstring_appendstr (dstr, "\\\"");
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
dstring_appendstr (dstr, "\\n");
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
dstring_appendstr (dstr, "\\t");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dasprintf (dstr, "\\x%02x", *s & 0xff);
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
str = s;
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_appendstr (dstr, "\"");
|
|
|
|
} else {
|
|
|
|
dstring_appendstr (dstr, "*** invalid string offset ***");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_float_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
if (data->pr->progs->version == PROG_ID_VERSION
|
2022-04-26 06:10:00 +00:00
|
|
|
&& ISDENORM (PR_PTR (int, value))
|
|
|
|
&& PR_PTR (uint, value) != 0x80000000) {
|
|
|
|
dasprintf (dstr, "<%08x>", PR_PTR (int, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
} else {
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "%.9g", PR_PTR (float, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void
|
|
|
|
pr_debug_vector_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
2004-01-31 04:26:01 +00:00
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "'%.9g %.9g %.9g'", VectorExpand (&PR_PTR (float, value)));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_entity_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
progs_t *pr = data->pr;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-01-16 13:15:18 +00:00
|
|
|
if (pr->pr_edicts
|
2022-04-26 06:10:00 +00:00
|
|
|
&& PR_PTR (entity, value) < pr->max_edicts
|
|
|
|
&& !(PR_PTR (entity, value) % pr->pr_edict_size)) {
|
|
|
|
edict_t *edict = PROG_TO_EDICT (pr, PR_PTR (entity, value));
|
2021-07-24 09:04:57 +00:00
|
|
|
if (edict) {
|
|
|
|
dasprintf (dstr, "entity %d", NUM_FOR_BAD_EDICT (pr, edict));
|
|
|
|
return;
|
|
|
|
}
|
2020-03-13 11:16:06 +00:00
|
|
|
}
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "entity [%x]", PR_PTR (entity, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_field_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
progs_t *pr = data->pr;
|
|
|
|
dstring_t *dstr = data->dstr;
|
2022-04-26 06:10:00 +00:00
|
|
|
pr_def_t *def = PR_FieldAtOfs (pr, PR_PTR (int, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
|
|
|
|
if (def) {
|
|
|
|
dasprintf (dstr, ".%s", PR_GetString (pr, def->name));
|
|
|
|
} else {
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, ".<$%04x>", PR_PTR (int, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_func_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
progs_t *pr = data->pr;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
if (PR_PTR (func, value) >= pr->progs->functions.count) {
|
|
|
|
dasprintf (dstr, "INVALID:%d", PR_PTR (func, value));
|
|
|
|
} else if (!PR_PTR (func, value)) {
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_appendstr (dstr, "NULL");
|
|
|
|
} else {
|
2022-04-26 06:10:00 +00:00
|
|
|
dfunction_t *f = pr->pr_functions + PR_PTR (func, value);
|
2021-12-31 06:02:31 +00:00
|
|
|
dasprintf (dstr, "%s()", PR_GetString (pr, f->name));
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-01-30 01:47:37 +00:00
|
|
|
pr_debug_ptr_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
2020-02-23 09:56:30 +00:00
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
progs_t *pr = data->pr;
|
|
|
|
dstring_t *dstr = data->dstr;
|
2022-04-26 06:10:00 +00:00
|
|
|
pr_ptr_t offset = PR_PTR (int, value);
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t offs = offset;
|
2020-02-24 02:28:43 +00:00
|
|
|
pr_def_t *def = 0;
|
2020-02-23 09:56:30 +00:00
|
|
|
|
2020-03-14 17:51:29 +00:00
|
|
|
def = pr_debug_find_def (pr, &offs);
|
2020-02-23 09:56:30 +00:00
|
|
|
if (def && def->name) {
|
2020-03-14 17:51:29 +00:00
|
|
|
if (offs) {
|
|
|
|
dasprintf (dstr, "&%s + %u", PR_GetString (pr, def->name), offs);
|
2004-01-31 04:26:01 +00:00
|
|
|
} else {
|
2020-03-14 17:51:29 +00:00
|
|
|
dasprintf (dstr, "&%s", PR_GetString (pr, def->name));
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
} else {
|
2020-03-14 17:51:29 +00:00
|
|
|
dasprintf (dstr, "[$%x]", offset);
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-01-30 01:47:37 +00:00
|
|
|
pr_debug_quaternion_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
2020-02-23 09:56:30 +00:00
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "'%.9g %.9g %.9g %.9g'", QuatExpand (&PR_PTR (float, value)));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-01-18 04:21:06 +00:00
|
|
|
pr_debug_int_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
2020-02-23 09:56:30 +00:00
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "%d", PR_PTR (int, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-01-18 04:21:06 +00:00
|
|
|
pr_debug_uint_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
2020-02-23 09:56:30 +00:00
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "$%08x", PR_PTR (uint, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_short_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "%04x", (short)PR_PTR (int, value));
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_double_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2020-03-13 05:57:33 +00:00
|
|
|
dasprintf (dstr, "%.17g", *(double *)value);
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 13:32:07 +00:00
|
|
|
static void
|
|
|
|
pr_debug_long_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
dasprintf (dstr, "%" PRIi64, *(int64_t *)value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_ulong_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
dasprintf (dstr, "%" PRIu64, *(uint64_t *)value);
|
|
|
|
}
|
|
|
|
|
2022-01-18 13:08:37 +00:00
|
|
|
static void
|
|
|
|
pr_debug_ushort_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
dasprintf (dstr, "%04x", (pr_ushort_t)PR_PTR (int, value));
|
2022-01-18 13:08:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
static void
|
2020-03-14 12:03:01 +00:00
|
|
|
pr_dump_struct (qfot_type_t *type, pr_type_t *value, void *_data,
|
|
|
|
const char *struct_type)
|
2020-02-23 09:56:30 +00:00
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
2020-03-13 05:56:56 +00:00
|
|
|
progs_t *pr = data->pr;
|
2020-02-23 09:56:30 +00:00
|
|
|
dstring_t *dstr = data->dstr;
|
2020-03-30 02:10:05 +00:00
|
|
|
qfot_struct_t *strct = &type->strct;
|
2020-03-13 05:56:56 +00:00
|
|
|
|
|
|
|
dstring_appendstr (dstr, "{");
|
|
|
|
for (int i = 0; i < strct->num_fields; i++) {
|
|
|
|
qfot_var_t *field = strct->fields + i;
|
|
|
|
qfot_type_t *val_type = &G_STRUCT (pr, qfot_type_t, field->type);
|
|
|
|
pr_type_t *val = value + field->offset;
|
|
|
|
dasprintf (dstr, "%s=", PR_GetString (pr, field->name));
|
|
|
|
value_string (data, val_type, val);
|
2020-03-14 12:03:01 +00:00
|
|
|
if (i < strct->num_fields - 1) {
|
2020-03-13 05:56:56 +00:00
|
|
|
dstring_appendstr (dstr, ", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dstring_appendstr (dstr, "}");
|
2020-03-14 12:03:01 +00:00
|
|
|
//dasprintf (dstr, "<%s>", struct_type);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
pr_debug_struct_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
pr_dump_struct (type, value, _data, "struct");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_union_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
pr_dump_struct (type, value, _data, "union");
|
2020-02-23 09:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_enum_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
dstring_appendstr (dstr, "<enum>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_array_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
dstring_appendstr (dstr, "<array>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_debug_class_view (qfot_type_t *type, pr_type_t *value, void *_data)
|
|
|
|
{
|
|
|
|
__auto_type data = (pr_debug_data_t *) _data;
|
|
|
|
dstring_t *dstr = data->dstr;
|
|
|
|
|
|
|
|
dstring_appendstr (dstr, "<class>");
|
2004-01-31 04:26:01 +00:00
|
|
|
}
|
|
|
|
|
2007-09-15 07:47:31 +00:00
|
|
|
VISIBLE void
|
|
|
|
PR_Debug_Watch (progs_t *pr, const char *expr)
|
|
|
|
{
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t watch;
|
2007-09-15 07:47:31 +00:00
|
|
|
if (!expr) {
|
|
|
|
Sys_Printf ("watch <watchpoint expr>\n");
|
|
|
|
if (pr->watch) {
|
|
|
|
Sys_Printf (" watching [%d]\n",
|
|
|
|
(int) (intptr_t) (pr->watch - pr->pr_globals));
|
|
|
|
if (pr->wp_conditional)
|
|
|
|
Sys_Printf (" if new val == %d\n",
|
2022-04-26 06:10:00 +00:00
|
|
|
PR_PTR (int, &pr->wp_val));
|
2020-02-23 09:56:30 +00:00
|
|
|
} else { Sys_Printf (" none active\n");
|
2007-09-15 07:47:31 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-06 14:48:31 +00:00
|
|
|
pr->watch = 0;
|
|
|
|
watch = parse_expression (pr, expr, 1);
|
|
|
|
if (watch.type != ev_invalid)
|
|
|
|
pr->watch = &pr->pr_globals[watch.ofs];
|
2007-09-15 07:47:31 +00:00
|
|
|
if (pr->watch) {
|
|
|
|
Sys_Printf ("watchpoint set to [%d]\n", PR_SetPointer (pr, pr->watch));
|
|
|
|
if (pr->wp_conditional)
|
2022-04-26 06:10:00 +00:00
|
|
|
Sys_Printf (" if new val == %d\n", PR_PTR (int, &pr->wp_val));
|
2007-09-15 07:47:31 +00:00
|
|
|
} else {
|
|
|
|
Sys_Printf ("watchpoint cleared\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
PR_Debug_Print (progs_t *pr, const char *expr)
|
|
|
|
{
|
2020-02-26 10:30:10 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t print;
|
2020-02-26 10:30:10 +00:00
|
|
|
pr_debug_data_t data = {pr, res->dstr};
|
2007-09-15 07:47:31 +00:00
|
|
|
|
|
|
|
if (!expr) {
|
|
|
|
Sys_Printf ("print <print expr>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-13 05:36:33 +00:00
|
|
|
print = parse_expression (pr, expr, 0);
|
2020-03-14 11:44:43 +00:00
|
|
|
if (print.type_encoding) {
|
|
|
|
qfot_type_t *type = get_type (res, print.type_encoding);
|
|
|
|
const char *s = global_string (&data, print.ofs, type, 1);
|
2011-09-06 14:48:31 +00:00
|
|
|
Sys_Printf ("[%d] = %s\n", print.ofs, s);
|
2007-09-15 07:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 01:56:57 +00:00
|
|
|
static const char *
|
|
|
|
print_raw_op (progs_t *pr, pr_ushort_t op, pr_ushort_t base_ind,
|
|
|
|
etype_t op_type, int op_width)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
const char *width = va (res->va, "%d", op_width);
|
|
|
|
return va (res->va, "%d:%04x<%08x>%s:%-8s",
|
|
|
|
base_ind, op, op + pr->pr_bases[base_ind],
|
|
|
|
op_width > 0 ? width : op_width < 0 ? "X" : "?",
|
|
|
|
pr_type_name[op_type]);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2007-04-04 12:30:49 +00:00
|
|
|
PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents)
|
2002-10-23 20:42:02 +00:00
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2007-04-04 12:30:49 +00:00
|
|
|
int addr = s - pr->pr_statements;
|
2007-04-09 06:16:03 +00:00
|
|
|
int dump_code = contents & 2;
|
2003-07-30 22:24:16 +00:00
|
|
|
const char *fmt;
|
2022-01-06 02:47:05 +00:00
|
|
|
const char *mnemonic;
|
2022-04-27 09:10:40 +00:00
|
|
|
const char *width = "";
|
2007-04-09 06:16:03 +00:00
|
|
|
dfunction_t *call_func = 0;
|
2022-01-27 01:55:06 +00:00
|
|
|
pr_def_t *param_def = 0;
|
2007-09-15 07:47:31 +00:00
|
|
|
pr_auxfunction_t *aux_func = 0;
|
2020-02-23 09:56:30 +00:00
|
|
|
pr_debug_data_t data;
|
2022-01-06 02:47:05 +00:00
|
|
|
etype_t op_type[3];
|
|
|
|
int op_width[3];
|
2003-07-30 22:24:16 +00:00
|
|
|
|
2020-02-26 16:25:41 +00:00
|
|
|
dstring_clearstr (res->line);
|
2003-07-30 22:24:16 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
data.pr = pr;
|
2020-02-26 10:30:10 +00:00
|
|
|
data.dstr = res->dstr;
|
2002-10-23 20:42:02 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug > 1)
|
2007-04-09 06:16:03 +00:00
|
|
|
dump_code = 1;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug && res->debug) {
|
2002-10-23 20:42:02 +00:00
|
|
|
const char *source_line = PR_Get_Source_Line (pr, addr);
|
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (source_line) {
|
2020-02-26 10:30:10 +00:00
|
|
|
dasprintf (res->line, "%s%s", source_line, dump_code ? "\n" : "");
|
2007-04-09 06:16:03 +00:00
|
|
|
if (!dump_code)
|
|
|
|
goto do_print;
|
|
|
|
}
|
|
|
|
if (!dump_code)
|
|
|
|
return;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 02:47:05 +00:00
|
|
|
if (pr->progs->version < PROG_VERSION) {
|
|
|
|
const v6p_opcode_t *op = PR_v6p_Opcode (s->op);
|
|
|
|
if (!op) {
|
|
|
|
Sys_Printf ("%sUnknown instruction %d\n", res->line->str, s->op);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VectorSet (op->type_a, op->type_b, op->type_c, op_type);
|
|
|
|
VectorSet (1, 1, 1, op_width);
|
|
|
|
fmt = op->fmt;
|
|
|
|
mnemonic = op->opname;
|
|
|
|
} else {
|
|
|
|
const opcode_t *op = PR_Opcode (s->op);
|
|
|
|
if (!op) {
|
|
|
|
Sys_Printf ("%sUnknown instruction %d\n", res->line->str, s->op);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
VectorCopy (op->widths, op_width);
|
|
|
|
VectorCopy (op->types, op_type);
|
|
|
|
fmt = op->fmt;
|
|
|
|
mnemonic = op->mnemonic;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 02:47:05 +00:00
|
|
|
if (!fmt) {
|
2003-07-30 22:24:44 +00:00
|
|
|
fmt = "%Ga, %Gb, %gc";
|
2022-01-06 02:47:05 +00:00
|
|
|
}
|
2003-07-30 22:24:16 +00:00
|
|
|
|
2020-02-26 10:30:10 +00:00
|
|
|
dasprintf (res->line, "%04x ", addr);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug > 2) {
|
2022-01-27 01:56:57 +00:00
|
|
|
if (pr->progs->version < PROG_VERSION) {
|
|
|
|
dasprintf (res->line,
|
|
|
|
"%03x %04x(%8s) %04x(%8s) %04x(%8s)\t",
|
|
|
|
s->op,
|
|
|
|
s->a, pr_type_name[op_type[0]],
|
|
|
|
s->b, pr_type_name[op_type[1]],
|
|
|
|
s->c, pr_type_name[op_type[2]]);
|
|
|
|
} else {
|
|
|
|
dasprintf (res->line, "%04x %s %s %s\t",
|
|
|
|
s->op,
|
|
|
|
print_raw_op (pr, s->a, PR_BASE_IND (s->op, A),
|
|
|
|
op_type[0], op_width[0]),
|
|
|
|
print_raw_op (pr, s->b, PR_BASE_IND (s->op, B),
|
2022-04-27 09:10:40 +00:00
|
|
|
op_type[1], op_width[1]),
|
2022-01-27 01:56:57 +00:00
|
|
|
print_raw_op (pr, s->c, PR_BASE_IND (s->op, C),
|
2022-04-27 09:10:40 +00:00
|
|
|
op_type[2], op_width[2]));
|
2022-01-27 01:56:57 +00:00
|
|
|
}
|
2022-04-27 09:10:40 +00:00
|
|
|
} else if (op_width[0] > 1 || op_width[1] > 1 || op_width[2] > 1) {
|
|
|
|
width = va (res->va, "{%d,%d,%d}", VectorExpand (op_width));
|
2022-01-06 02:47:05 +00:00
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
|
2022-04-27 09:10:40 +00:00
|
|
|
dasprintf (res->line, "%s%s ", mnemonic, width);
|
2003-07-30 22:24:16 +00:00
|
|
|
|
|
|
|
while (*fmt) {
|
|
|
|
if (*fmt == '%') {
|
|
|
|
if (fmt[1] == '%') {
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_appendsubstr (res->line, fmt + 1, 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
fmt += 2;
|
|
|
|
} else {
|
2004-01-30 07:55:32 +00:00
|
|
|
const char *str;
|
2005-01-02 14:23:20 +00:00
|
|
|
char mode = fmt[1], opchar = fmt[2];
|
2022-01-27 01:55:06 +00:00
|
|
|
unsigned param_ind = 0;
|
2022-01-27 04:29:38 +00:00
|
|
|
pr_uint_t shift = 0;
|
2022-01-27 05:16:05 +00:00
|
|
|
pr_uint_t opreg;
|
2022-01-02 11:46:32 +00:00
|
|
|
pr_uint_t opval;
|
2020-03-14 14:38:22 +00:00
|
|
|
qfot_type_t *optype = &res->void_type;
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t func;
|
2003-07-30 22:24:16 +00:00
|
|
|
|
2007-04-09 06:16:03 +00:00
|
|
|
if (mode == 'P') {
|
|
|
|
opchar = fmt[3];
|
2022-01-27 01:55:06 +00:00
|
|
|
param_ind = fmt[2] - '0';
|
2007-04-09 06:16:03 +00:00
|
|
|
fmt++; // P has one extra item
|
2022-01-27 01:55:06 +00:00
|
|
|
if (param_ind >= PR_MAX_PARAMS)
|
2007-04-09 06:16:03 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2022-01-27 04:29:38 +00:00
|
|
|
if (mode == 'M' || mode == 'm') {
|
|
|
|
if (!isxdigit (fmt[3])) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
shift = fmt[3];
|
|
|
|
shift = (shift & 0xf)
|
|
|
|
+ (((shift & 0x40) >> 3) | ((shift & 0x40) >> 5));
|
|
|
|
fmt++; // M/m have one extra item
|
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
|
2003-07-30 22:24:16 +00:00
|
|
|
switch (opchar) {
|
|
|
|
case 'a':
|
2022-01-27 05:16:05 +00:00
|
|
|
opreg = PR_BASE_IND (s->op, A);
|
2003-07-30 22:24:16 +00:00
|
|
|
opval = s->a;
|
2022-01-06 02:47:05 +00:00
|
|
|
optype = res->type_encodings[op_type[0]];
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
2022-01-27 05:16:05 +00:00
|
|
|
opreg = PR_BASE_IND (s->op, B);
|
2003-07-30 22:24:16 +00:00
|
|
|
opval = s->b;
|
2022-01-06 02:47:05 +00:00
|
|
|
optype = res->type_encodings[op_type[1]];
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
2022-01-27 05:16:05 +00:00
|
|
|
opreg = PR_BASE_IND (s->op, C);
|
2003-07-30 22:24:16 +00:00
|
|
|
opval = s->c;
|
2022-01-06 02:47:05 +00:00
|
|
|
optype = res->type_encodings[op_type[2]];
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
2022-01-27 05:16:05 +00:00
|
|
|
case 'o':
|
|
|
|
opreg = 0;
|
|
|
|
opval = s->op;
|
|
|
|
break;
|
2007-04-09 06:16:03 +00:00
|
|
|
case 'x':
|
|
|
|
if (mode == 'P') {
|
2022-01-27 01:55:06 +00:00
|
|
|
opval = pr->pr_real_params[param_ind]
|
2007-04-09 06:16:03 +00:00
|
|
|
- pr->pr_globals;
|
|
|
|
break;
|
|
|
|
}
|
2022-01-27 05:16:05 +00:00
|
|
|
goto err;
|
2003-07-30 22:24:16 +00:00
|
|
|
default:
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
switch (mode) {
|
2007-09-15 07:47:31 +00:00
|
|
|
case 'R':
|
2020-03-14 14:38:22 +00:00
|
|
|
optype = &res->void_type;
|
2007-09-15 07:47:31 +00:00
|
|
|
aux_func = get_aux_function (pr);
|
2020-03-14 11:44:43 +00:00
|
|
|
if (aux_func) {
|
|
|
|
optype = get_type (res, aux_func->return_type);
|
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype,
|
|
|
|
contents & 1);
|
2007-09-15 07:47:31 +00:00
|
|
|
break;
|
2007-04-09 06:16:03 +00:00
|
|
|
case 'F':
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype,
|
|
|
|
contents & 1);
|
2020-02-25 12:23:13 +00:00
|
|
|
func = G_FUNCTION (pr, opval);
|
2022-01-26 10:30:25 +00:00
|
|
|
if (func < pr->progs->functions.count) {
|
2020-02-25 12:23:13 +00:00
|
|
|
call_func = pr->pr_functions + func;
|
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
2022-01-27 01:55:06 +00:00
|
|
|
param_def = PR_Get_Param_Def (pr, call_func, param_ind);
|
2020-03-14 14:38:22 +00:00
|
|
|
optype = &res->void_type;
|
2022-01-27 01:55:06 +00:00
|
|
|
if (param_def) {
|
|
|
|
optype = get_type (res, param_def->type_encoding);
|
2020-03-14 11:44:43 +00:00
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype,
|
|
|
|
contents & 1);
|
2007-04-09 06:16:03 +00:00
|
|
|
break;
|
2003-07-30 22:24:16 +00:00
|
|
|
case 'V':
|
2022-01-27 05:16:05 +00:00
|
|
|
opval += pr->pr_bases[opreg];
|
2022-03-30 17:48:01 +00:00
|
|
|
optype = &res->void_type;
|
|
|
|
str = global_string (&data, opval, optype,
|
2020-02-23 09:56:30 +00:00
|
|
|
contents & 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
2022-01-27 05:16:05 +00:00
|
|
|
opval += pr->pr_bases[opreg];
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype,
|
|
|
|
contents & 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
2022-01-27 05:16:05 +00:00
|
|
|
opval += pr->pr_bases[opreg];
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype, 0);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2020-02-26 10:30:10 +00:00
|
|
|
str = dsprintf (res->dva, "%d", (short) opval);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
|
|
|
case 'O':
|
2020-02-26 10:30:10 +00:00
|
|
|
str = dsprintf (res->dva, "%04x",
|
|
|
|
addr + (short) opval);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
2022-01-21 01:12:50 +00:00
|
|
|
case 'C':
|
|
|
|
str = dsprintf (res->dva, "%03o", opval);
|
|
|
|
break;
|
2010-11-19 15:31:34 +00:00
|
|
|
case 'E':
|
|
|
|
{
|
2011-03-06 23:28:20 +00:00
|
|
|
edict_t *ed = 0;
|
2022-04-26 06:10:00 +00:00
|
|
|
opval = G_ENTITY (pr, s->a);
|
|
|
|
param_ind = G_FIELD (pr, s->b);
|
2022-01-27 01:55:06 +00:00
|
|
|
if (param_ind < pr->progs->entityfields
|
2021-06-27 05:47:08 +00:00
|
|
|
&& opval > 0
|
2013-01-17 05:11:54 +00:00
|
|
|
&& opval < pr->pr_edict_area_size) {
|
2010-11-19 15:31:34 +00:00
|
|
|
ed = PROG_TO_EDICT (pr, opval);
|
2022-01-27 01:55:06 +00:00
|
|
|
opval = &E_fld(ed, param_ind) - pr->pr_globals;
|
2011-03-06 23:28:20 +00:00
|
|
|
}
|
|
|
|
if (!ed) {
|
2010-11-19 15:31:34 +00:00
|
|
|
str = "bad entity.field";
|
|
|
|
break;
|
|
|
|
}
|
2020-02-23 09:56:30 +00:00
|
|
|
str = global_string (&data, opval, optype,
|
2013-01-17 07:42:28 +00:00
|
|
|
contents & 1);
|
2020-02-26 10:30:10 +00:00
|
|
|
str = dsprintf (res->dva, "$%x $%x %s",
|
|
|
|
s->a, s->b, str);
|
2010-11-19 15:31:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-01-27 04:29:38 +00:00
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
{
|
|
|
|
pr_ptr_t ptr = 0;
|
|
|
|
pr_int_t offs = 0;
|
|
|
|
switch ((opval >> shift) & 3) {
|
|
|
|
case 0:
|
|
|
|
ptr = s->a + PR_BASE (pr, s, A);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ptr = s->a + PR_BASE (pr, s, A);
|
|
|
|
ptr = G_POINTER (pr, ptr);
|
|
|
|
offs = (short) s->b;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ptr = s->a + PR_BASE (pr, s, A);
|
|
|
|
ptr = G_POINTER (pr, ptr);
|
|
|
|
offs = s->b + PR_BASE (pr, s, B);
|
|
|
|
offs = G_INT (pr, offs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr += offs;
|
|
|
|
str = global_string (&data, ptr, optype,
|
|
|
|
mode == 'M');
|
|
|
|
}
|
|
|
|
break;
|
2003-07-30 22:24:16 +00:00
|
|
|
default:
|
|
|
|
goto err;
|
|
|
|
}
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_appendstr (res->line, str);
|
2003-07-30 22:24:16 +00:00
|
|
|
fmt += 3;
|
|
|
|
continue;
|
|
|
|
err:
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_appendstr (res->line, fmt);
|
2003-07-30 22:24:16 +00:00
|
|
|
break;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
2003-07-30 22:24:16 +00:00
|
|
|
} else {
|
2020-02-26 10:30:10 +00:00
|
|
|
dstring_appendsubstr (res->line, fmt++, 1);
|
2003-07-30 22:24:16 +00:00
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
2007-04-09 06:16:03 +00:00
|
|
|
do_print:
|
2020-02-26 10:30:10 +00:00
|
|
|
Sys_Printf ("%s\n", res->line->str);
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 07:10:32 +00:00
|
|
|
static void
|
|
|
|
dump_frame (progs_t *pr, prstack_t *frame)
|
|
|
|
{
|
2020-02-25 11:07:29 +00:00
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
2020-04-02 06:00:01 +00:00
|
|
|
dfunction_t *f = frame->func ? frame->func->descriptor : 0;
|
2004-01-05 07:10:32 +00:00
|
|
|
|
|
|
|
if (!f) {
|
|
|
|
Sys_Printf ("<NO FUNCTION>\n");
|
|
|
|
return;
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (pr_debug && res->debug) {
|
2020-04-02 06:00:01 +00:00
|
|
|
pr_lineno_t *lineno = PR_Find_Lineno (pr, frame->staddr);
|
2004-01-05 07:10:32 +00:00
|
|
|
pr_auxfunction_t *func = PR_Get_Lineno_Func (pr, lineno);
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_uint_t line = PR_Get_Lineno_Line (pr, lineno);
|
2022-01-17 05:43:43 +00:00
|
|
|
pr_uint_t addr = PR_Get_Lineno_Addr (pr, lineno);
|
2004-01-05 07:10:32 +00:00
|
|
|
|
|
|
|
line += func->source_line;
|
2020-04-02 06:00:01 +00:00
|
|
|
if (addr == frame->staddr) {
|
2007-04-06 00:47:41 +00:00
|
|
|
Sys_Printf ("%12s:%u : %s: %x\n",
|
2021-12-31 06:02:31 +00:00
|
|
|
PR_GetString (pr, f->file),
|
2004-01-05 07:10:32 +00:00
|
|
|
line,
|
2021-12-31 06:02:31 +00:00
|
|
|
PR_GetString (pr, f->name),
|
2020-04-02 06:00:01 +00:00
|
|
|
frame->staddr);
|
2004-01-05 07:10:32 +00:00
|
|
|
} else {
|
2007-04-06 00:47:41 +00:00
|
|
|
Sys_Printf ("%12s:%u+%d : %s: %x\n",
|
2021-12-31 06:02:31 +00:00
|
|
|
PR_GetString (pr, f->file),
|
2020-04-02 06:00:01 +00:00
|
|
|
line, frame->staddr - addr,
|
2021-12-31 06:02:31 +00:00
|
|
|
PR_GetString (pr, f->name),
|
2020-04-02 06:00:01 +00:00
|
|
|
frame->staddr);
|
2004-01-05 07:10:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-31 06:02:31 +00:00
|
|
|
Sys_Printf ("%12s : %s: %x\n", PR_GetString (pr, f->file),
|
|
|
|
PR_GetString (pr, f->name), frame->staddr);
|
2004-01-05 07:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-10 09:45:57 +00:00
|
|
|
VISIBLE void
|
2004-01-05 07:10:32 +00:00
|
|
|
PR_StackTrace (progs_t *pr)
|
2002-10-23 20:42:02 +00:00
|
|
|
{
|
2007-04-04 12:30:49 +00:00
|
|
|
int i;
|
|
|
|
prstack_t top;
|
2002-10-23 20:42:02 +00:00
|
|
|
|
|
|
|
if (pr->pr_depth == 0) {
|
|
|
|
Sys_Printf ("<NO STACK>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-02 06:00:01 +00:00
|
|
|
top.staddr = pr->pr_xstatement;
|
|
|
|
top.func = pr->pr_xfunction;
|
2004-01-05 07:10:32 +00:00
|
|
|
dump_frame (pr, &top);
|
|
|
|
for (i = pr->pr_depth - 1; i >= 0; i--)
|
|
|
|
dump_frame (pr, pr->pr_stack + i);
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-10-23 20:42:02 +00:00
|
|
|
PR_Profile (progs_t * pr)
|
|
|
|
{
|
2022-02-04 12:49:59 +00:00
|
|
|
pr_ulong_t max, num, i;
|
|
|
|
pr_ulong_t total;
|
2021-12-27 04:50:49 +00:00
|
|
|
dfunction_t *f;
|
|
|
|
bfunction_t *best, *bf;
|
2002-10-23 20:42:02 +00:00
|
|
|
|
|
|
|
num = 0;
|
2022-02-04 12:49:59 +00:00
|
|
|
total = 0;
|
|
|
|
for (i = 0; i < pr->progs->functions.count; i++) {
|
|
|
|
bf = &pr->function_table[i];
|
|
|
|
total += bf->profile;
|
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
do {
|
|
|
|
max = 0;
|
|
|
|
best = NULL;
|
2022-01-26 10:30:25 +00:00
|
|
|
for (i = 0; i < pr->progs->functions.count; i++) {
|
2021-12-27 04:50:49 +00:00
|
|
|
bf = &pr->function_table[i];
|
|
|
|
if (bf->profile > max) {
|
|
|
|
max = bf->profile;
|
|
|
|
best = bf;
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best) {
|
2021-12-27 04:50:49 +00:00
|
|
|
if (num < 10) {
|
|
|
|
f = pr->pr_functions + (best - pr->function_table);
|
2022-02-04 12:49:59 +00:00
|
|
|
Sys_Printf ("%7"PRIu64" %s%s\n", best->profile,
|
|
|
|
PR_GetString (pr, f->name),
|
|
|
|
f->first_statement < 0 ? " (builtin)" : "");
|
2021-12-27 04:50:49 +00:00
|
|
|
}
|
2002-10-23 20:42:02 +00:00
|
|
|
num++;
|
|
|
|
best->profile = 0;
|
|
|
|
}
|
|
|
|
} while (best);
|
2022-02-04 12:49:59 +00:00
|
|
|
Sys_Printf ("total: %7"PRIu64"\n", total);
|
2002-10-23 20:42:02 +00:00
|
|
|
}
|
2004-01-30 08:46:14 +00:00
|
|
|
|
2021-07-25 00:54:08 +00:00
|
|
|
static void
|
|
|
|
print_field (progs_t *pr, edict_t *ed, pr_def_t *d)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = pr->pr_debug_resources;
|
|
|
|
int l;
|
|
|
|
pr_type_t *v;
|
|
|
|
qfot_type_t dummy_type = { };
|
|
|
|
qfot_type_t *type;
|
|
|
|
pr_debug_data_t data = {pr, res->dstr};
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = PR_GetString (pr, d->name);
|
|
|
|
type = get_def_type (pr, d, &dummy_type);
|
|
|
|
v = &E_fld (ed, d->ofs);
|
|
|
|
|
|
|
|
l = 15 - strlen (name);
|
|
|
|
if (l < 1)
|
|
|
|
l = 1;
|
|
|
|
|
|
|
|
dstring_clearstr (res->dstr);
|
|
|
|
value_string (&data, type, v);
|
|
|
|
Sys_Printf ("%s%*s%s\n", name, l, "", res->dstr->str);
|
|
|
|
}
|
|
|
|
|
2004-01-30 08:46:14 +00:00
|
|
|
/*
|
|
|
|
ED_Print
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2021-07-25 00:54:08 +00:00
|
|
|
ED_Print (progs_t *pr, edict_t *ed, const char *fieldname)
|
2004-01-30 08:46:14 +00:00
|
|
|
{
|
2020-02-23 14:29:58 +00:00
|
|
|
pr_uint_t i, j;
|
2004-01-30 08:46:14 +00:00
|
|
|
const char *name;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *d;
|
2021-07-25 00:54:08 +00:00
|
|
|
int l;
|
2004-01-30 08:46:14 +00:00
|
|
|
|
|
|
|
if (ed->free) {
|
|
|
|
Sys_Printf ("FREE\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-09 08:55:24 +00:00
|
|
|
Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed));
|
2021-07-25 00:54:08 +00:00
|
|
|
|
|
|
|
if (fieldname) {
|
|
|
|
d = PR_FindField(pr, fieldname);
|
|
|
|
if (!d) {
|
|
|
|
Sys_Printf ("unknown field '%s'\n", fieldname);
|
|
|
|
} else {
|
|
|
|
print_field (pr, ed, d);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-01-26 10:30:25 +00:00
|
|
|
for (i = 0; i < pr->progs->fielddefs.count; i++) {
|
2004-01-30 08:46:14 +00:00
|
|
|
d = &pr->pr_fielddefs[i];
|
2020-02-22 13:33:44 +00:00
|
|
|
if (!d->name) // null field def (probably 1st)
|
2004-01-30 08:46:14 +00:00
|
|
|
continue;
|
2020-02-22 13:33:44 +00:00
|
|
|
name = PR_GetString (pr, d->name);
|
2021-07-25 00:54:08 +00:00
|
|
|
l = strlen (name);
|
|
|
|
if (l >= 2 && name[l - 2] == '_' && strchr ("xyz", name[l - 1]))
|
2004-01-30 08:46:14 +00:00
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
2021-12-27 10:02:39 +00:00
|
|
|
qfot_type_t dummy_type = { };
|
|
|
|
get_def_type (pr, d, &dummy_type);
|
2020-02-23 14:29:58 +00:00
|
|
|
for (j = 0; j < d->size; j++) {
|
|
|
|
if (E_INT (ed, d->ofs + j)) {
|
2004-01-30 08:46:14 +00:00
|
|
|
break;
|
2020-02-23 14:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j == d->size) {
|
|
|
|
continue;
|
2004-01-30 08:46:14 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 00:54:08 +00:00
|
|
|
print_field (pr, ed, d);
|
2004-01-30 08:46:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-25 11:07:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
PR_Debug_Init (progs_t *pr)
|
|
|
|
{
|
|
|
|
prdeb_resources_t *res = calloc (1, sizeof (*res));
|
|
|
|
res->pr = pr;
|
2020-02-26 10:30:10 +00:00
|
|
|
res->string = dstring_newstr ();
|
|
|
|
res->dva = dstring_newstr ();
|
|
|
|
res->line = dstring_newstr ();
|
|
|
|
res->dstr = dstring_newstr ();
|
2022-01-27 01:56:57 +00:00
|
|
|
res->va = va_create_context (8);
|
2020-02-25 11:07:29 +00:00
|
|
|
|
2020-03-14 11:44:43 +00:00
|
|
|
res->void_type.meta = ty_basic;
|
|
|
|
res->void_type.size = 4;
|
|
|
|
res->void_type.encoding = 0;
|
2020-03-30 02:10:05 +00:00
|
|
|
res->void_type.type = ev_void;
|
2020-03-14 11:44:43 +00:00
|
|
|
for (int i = 0; i < ev_type_count; i++ ) {
|
|
|
|
res->type_encodings[i] = &res->void_type;
|
|
|
|
}
|
2020-04-04 03:50:25 +00:00
|
|
|
res->file_hash = Hash_NewTable (509, file_get_key, file_free, 0,
|
|
|
|
pr->hashlink_freelist);
|
|
|
|
res->debug_syms = Hash_NewTable (509, def_get_key, 0, pr,
|
|
|
|
pr->hashlink_freelist);
|
|
|
|
res->compunits = Hash_NewTable (509, compunit_get_key, 0, pr,
|
2020-04-03 13:39:27 +00:00
|
|
|
pr->hashlink_freelist);
|
2020-03-14 11:44:43 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
PR_Resources_Register (pr, "PR_Debug", res, pr_debug_clear);
|
2021-12-26 11:35:09 +00:00
|
|
|
pr->pr_debug_resources = res;
|
2020-02-25 11:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PR_Debug_Init_Cvars (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&pr_debug_cvar, 0, 0);
|
|
|
|
Cvar_Register (&pr_source_path_cvar, source_path_f, 0);
|
2020-02-25 11:07:29 +00:00
|
|
|
}
|