forked from fte/fteqw
1
0
Fork 0

qclib: Sort QC function entries, in an attempt to support breakpoints where functions have been reordered for one reason or another.

fteqcc: fix some statement-line numbers that were buggy. This fixes breakpoints not working with recent versions of fteqcc.


git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5286 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2018-08-04 15:12:51 +00:00
parent 60afec2445
commit aede46c776
4 changed files with 122 additions and 73 deletions

View File

@ -1330,9 +1330,9 @@ reeval:
break; break;
*/ */
default: default:
if (op & 0x8000) //break point! if (op & OP_BIT_BREAKPOINT) //break point!
{ {
op &= ~0x8000; op &= ~OP_BIT_BREAKPOINT;
s = st-pr_statements; s = st-pr_statements;
if (pr_xstatement != s) if (pr_xstatement != s)
{ {
@ -1341,7 +1341,7 @@ reeval:
s = ShowStep(progfuncs, s, NULL, false); s = ShowStep(progfuncs, s, NULL, false);
st = &pr_statements[s]; //let the user move execution st = &pr_statements[s]; //let the user move execution
pr_xstatement = s = st-pr_statements; pr_xstatement = s = st-pr_statements;
op = st->op & ~0x8000; op = st->op & ~OP_BIT_BREAKPOINT;
} }
goto reeval; //reexecute goto reeval; //reexecute
} }

View File

@ -436,6 +436,8 @@ enum qcop_e {
OPD_GOTO_FORSTART, OPD_GOTO_FORSTART,
OPD_GOTO_WHILE1, OPD_GOTO_WHILE1,
OP_BIT_BREAKPOINT = 0x8000,
OP_NUMOPS OP_NUMOPS
}; };

View File

@ -10,6 +10,12 @@
#define fte_restrict #define fte_restrict
#endif #endif
#if defined(_WIN32) || defined(__DJGPP__)
#include <malloc.h>
#elif !defined(alloca) //alloca.h isn't present on bsd (stdlib.h should define it to __builtin_alloca, and we can check for that here).
#include <alloca.h>
#endif
#define HunkAlloc BADGDFG sdfhhsf FHS #define HunkAlloc BADGDFG sdfhhsf FHS
@ -360,7 +366,8 @@ void PDECL PR_StackTrace (pubprogfuncs_t *ppf, int showlocals)
{ {
progfuncs_t *progfuncs = (progfuncs_t *)ppf; progfuncs_t *progfuncs = (progfuncs_t *)ppf;
const mfunction_t *f; const mfunction_t *f;
int i; int prnum;
int i, st;
int progs; int progs;
int ofs; int ofs;
int *globalbase; int *globalbase;
@ -378,11 +385,20 @@ void PDECL PR_StackTrace (pubprogfuncs_t *ppf, int showlocals)
//point this to the function's locals //point this to the function's locals
globalbase = (int *)pr_globals + pr_xfunction->parm_start + pr_xfunction->locals; globalbase = (int *)pr_globals + pr_xfunction->parm_start + pr_xfunction->locals;
pr_stack[pr_depth].f = pr_xfunction;
pr_stack[pr_depth].s = pr_xstatement;
for (i=pr_depth ; i>0 ; i--) for (i=pr_depth ; i>0 ; i--)
{
if (i == pr_depth)
{
f = pr_xfunction;
st = pr_xstatement;
prnum = prinst.pr_typecurrent;
}
else
{ {
f = pr_stack[i].f; f = pr_stack[i].f;
st = pr_stack[i].s;
prnum = pr_stack[i].progsnum;
}
if (!f) if (!f)
{ {
@ -392,9 +408,9 @@ void PDECL PR_StackTrace (pubprogfuncs_t *ppf, int showlocals)
{ {
globalbase -= f->locals; globalbase -= f->locals;
if (pr_stack[i].progsnum != progs) if (prnum != progs)
{ {
progs = pr_stack[i].progsnum; progs = prnum;
printf ("<%s>\n", pr_progstate[progs].filename); printf ("<%s>\n", pr_progstate[progs].filename);
} }
@ -402,7 +418,6 @@ void PDECL PR_StackTrace (pubprogfuncs_t *ppf, int showlocals)
printf ("stripped : %s\n", PR_StringToNative(ppf, f->s_name)); printf ("stripped : %s\n", PR_StringToNative(ppf, f->s_name));
else else
{ {
int st = pr_stack[i].s;
if (pr_progstate[progs].linenums) if (pr_progstate[progs].linenums)
printf ("%12s:%i: %s\n", PR_StringToNative(ppf, f->s_file), pr_progstate[progs].linenums[st], PR_StringToNative(ppf, f->s_name)); printf ("%12s:%i: %s\n", PR_StringToNative(ppf, f->s_file), pr_progstate[progs].linenums[st], PR_StringToNative(ppf, f->s_name));
else else
@ -1092,12 +1107,26 @@ void SetExecutionToLine(progfuncs_t *progfuncs, int linenum)
// EditorHighlightLine(editwnd, pr_progstate[pn].linenums[snum]); // EditorHighlightLine(editwnd, pr_progstate[pn].linenums[snum]);
} }
struct sortedfunc_s
{
int firststatement;
int firstline;
};
int PDECL PR_SortBreakFunctions(const void *va, const void *vb)
{
const struct sortedfunc_s *a = va;
const struct sortedfunc_s *b = vb;
if (a->firstline == b->firstline)
return 0;
return a->firstline > b->firstline;
}
//0 clear. 1 set, 2 toggle, 3 check //0 clear. 1 set, 2 toggle, 3 check
int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum, int flag) //write alternate route to work by function name. int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum, int flag) //write alternate route to work by function name.
{ {
progfuncs_t *progfuncs = (progfuncs_t*)ppf; progfuncs_t *progfuncs = (progfuncs_t*)ppf;
int ret=0; int ret=0;
unsigned int fl; unsigned int fl, stline;
unsigned int i; unsigned int i;
int pn = prinst.pr_typecurrent; int pn = prinst.pr_typecurrent;
mfunction_t *f; mfunction_t *f;
@ -1110,8 +1139,11 @@ int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum,
if (linenum) //linenum is set means to set the breakpoint on a file and line if (linenum) //linenum is set means to set the breakpoint on a file and line
{ {
struct sortedfunc_s *sortedstatements;
int numfilefunctions = 0;
if (!pr_progstate[pn].linenums) if (!pr_progstate[pn].linenums)
continue; continue;
sortedstatements = alloca(pr_progstate[pn].progs->numfunctions * sizeof(*sortedstatements));
//we need to use the function table in order to set breakpoints in the right file. //we need to use the function table in order to set breakpoints in the right file.
for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++) for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++)
@ -1121,14 +1153,28 @@ int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum,
fncfile+=2; fncfile+=2;
if (!stricmp(fncfile, filename)) if (!stricmp(fncfile, filename))
{ {
for (i = f->first_statement; i < pr_progstate[pn].progs->numstatements; i++) sortedstatements[numfilefunctions].firststatement = f->first_statement;
if (f->first_statement < 0 || f->first_statement >= (int)pr_progstate[pn].progs->numstatements)
sortedstatements[numfilefunctions].firstline = 0;
else
sortedstatements[numfilefunctions].firstline = pr_progstate[pn].linenums[f->first_statement];
numfilefunctions++;
}
}
f = NULL;
qsort(sortedstatements, numfilefunctions, sizeof(*sortedstatements), PR_SortBreakFunctions);
//our functions are now in terms of ascending line numbers.
for (fl = 0; fl < numfilefunctions; fl++)
{
for (i = sortedstatements[fl].firststatement; i < pr_progstate[pn].progs->numstatements; i++)
{ {
if (pr_progstate[pn].linenums[i] >= linenum) if (pr_progstate[pn].linenums[i] >= linenum)
{ {
fl = pr_progstate[pn].linenums[i]; stline = pr_progstate[pn].linenums[i];
for (; ; i++) for (; ; i++)
{ {
if ((unsigned int)pr_progstate[pn].linenums[i] > fl) if ((unsigned int)pr_progstate[pn].linenums[i] != stline)
break; break;
switch(pr_progstate[pn].structtype) switch(pr_progstate[pn].structtype)
@ -1148,29 +1194,29 @@ int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum,
switch (flag) switch (flag)
{ {
default: default:
if (op & 0x8000) if (op & OP_BIT_BREAKPOINT)
{ {
op &= ~0x8000; op &= ~OP_BIT_BREAKPOINT;
ret = false; ret = false;
flag = 0; flag = 0;
} }
else else
{ {
op |= 0x8000; op |= OP_BIT_BREAKPOINT;
ret = true; ret = true;
flag = 1; flag = 1;
} }
break; break;
case 0: case 0:
op &= ~0x8000; op &= ~OP_BIT_BREAKPOINT;
ret = false; ret = false;
break; break;
case 1: case 1:
op |= 0x8000; op |= OP_BIT_BREAKPOINT;
ret = true; ret = true;
break; break;
case 3: case 3:
if (op & 0x8000) if (op & OP_BIT_BREAKPOINT)
return true; return true;
} }
switch(pr_progstate[pn].structtype) switch(pr_progstate[pn].structtype)
@ -1195,7 +1241,6 @@ int PDECL PR_ToggleBreakpoint(pubprogfuncs_t *ppf, char *filename, int linenum,
} }
} }
} }
}
else //set the breakpoint on the first statement of the function specified. else //set the breakpoint on the first statement of the function specified.
{ {
for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++) for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++)

View File

@ -171,6 +171,8 @@ static void QCC_PR_IncludeChunkEx (char *data, pbool duplicate, char *filename,
#endif #endif
cnst->inside++; cnst->inside++;
} }
else
pr_source_line = 1;
if (duplicate) if (duplicate)
{ {