UPS C Interpreter/Debugger fixes for RedHat 5.1/Linux 2.0.34

From: Dibyendu Majumdar (dibyendu_at_mazumdar.demon.co.uk)
Date: Thu Dec 03 1998 - 00:05:22 GMT


Ian,

I have fixed a couple of more problems when debugging CX executables
with UPS 3.33. I have been building UPS, CX, XC and CG on RedHat 5.1
(intel)
(Linux 2.0.34).

Following summarises ALL the fixes so far:

C Interpreter
-------------

1. The UPS C interpreter executables could not be built initially
because
   of missing references to demangle_name_2().

2. CX and CG failed because of libvar botch. This was caused by cc.c not

   including the same headers (particularly <mtrprog/ifdefs.h>) as
   xc_builtins.c.

3. stderr, stdout, stderr, errno were inaccessible from interpreted
code.
   Now they can be accessed (readonly) by defining following macros:

   #define stderr _stderr_()
   #define stdout _stdout_()
   #define stdin  _stdin_()
   #define errno _errno_()

Deficiencies in the C Interpreter
---------------------------------
So far, I have found the following deficiencies in the interpreter:

1. Following does not work:

    typedef enum bool bool;
    enum bool { false, true };

    However, rearranging above as follows works:

    enum bool { false, true };
    typedef enum bool bool;

2. enum values are not automatically converted to int - example,
following code
    does not work:

    extern int printf(const char *, ...);

    enum bool { false, true };
    typedef enum bool bool;

    int main(void)
    {
        bool boolean = true;
        int integer = true; // fails
        printf("boolean = %s\n", boolean ? "true" : "false"); // fails

        return 0;
    }

3. The increment (++) or decrement (--) operators do not work with
   floating point values.

4. Double values cannot be returned from external C routines called from

   interpreted code. This means standard C functions such as atof(),
   difftime() cannot be called from interpreted code.

   However, an interpreted atof() works.

5. Arrays and structures cannot be initialised in functions. For
example,
   this doesn't work:

   int func(void)
   {
      int array[] = { 1, 2 };
   }

UPS Debugger
------------

I think I have fixed some problems in the UPS debugger when debugging
CX executables:

1. The debugger aborted with segmentation fault because
demangle_name_2()
   did not recognise CX executables. My solution is described in the
   diff, but is dubious.

2. The debugger complained that there was no line number information
   despite compiling with -g flag.

3. The debugger aborted with segmentation fault in open_source_file()
   in st_util.c.

4. When debugging an executable linked from several sources, the
debugger
   was unable to step into code that was in a different source.

5. The debugger could not step through code generated from some switch
   statements (SWITCH_ON_CHAIN category). The program behaved
incorrectly
   when attempting to do so.

6. The debugger failed with segmentation fault when attempting to step
   through a switch statement.

Outstanding problems in UPS Debugger
------------------------------------
I still cannot debug a C source file directly. The same problem as in
(3) above. Haven't figured out how to fix it.

NEXT doesnot work always (specially when stepping over a function).
It causes UPS to panic (graj NYI).

Another thing
-------------
I am using UPS to debug UPS itself. Has worked fine so far.

Diffs
----
A diff is attached.

Thanks and Regards


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./Makefile differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22c22
< X11INCLUDE=-I/usr/openwin/include
---
> #X11INCLUDE=-I/usr/openwin/include
30c30
< #X11LIB = /usr/X11/lib/libX11.a
---
> X11LIB = /usr/X11R6/lib/libX11.a
59,60c59,60
< CC = cc
< CFLAGS = -g
---
> CC = gcc
> CFLAGS = -g -Wall -DOS_LINUX
63,65c63,65
< RANLIB = :
< SVR4_LINKFLAGS=-R/usr/openwin/lib -L/usr/openwin/lib
< LINKFLAGS = ${SVR4_LINKFLAGS}
---
> #RANLIB = :
> #SVR4_LINKFLAGS=-R/usr/openwin/lib -L/usr/openwin/lib
> #LINKFLAGS = ${SVR4_LINKFLAGS}
68c68
< #RANLIB = ranlib
---
> RANLIB = ranlib
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./lib/libedit/render.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
750c750,751
< 			    *iptr++;
---
>                             /* Ladanyi */
> 			    iptr++;
865c866,867
< 	    *iptr++;
---
>             /* Ladanyi */
> 	    iptr++;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_target.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22a23,27
> /* Ladanyi */
> #ifdef OS_LINUX
> #include <sys/reg.h>
> #endif
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_ptrace.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110a111,116
> /* Ladanyi */
> #if defined(OS_LINUX)
> #include <sys/ptrace.h>
> #include <sys/reg.h>
> #endif
> 
118d123
< #if defined(OS_LINUX)
120a126,128
> #if defined(OS_LINUX)
> 
> /** Ladanyi - commented out
122a131
> */
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_symload.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100c100,101
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined (OS_LINUX)
384c385,386
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined(OS_LINUX)
1820c1822,1823
<     return TRUE;
---
>     /* Dibyendu */
>     return likely;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_symparse.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
564c564,565
< #ifdef OS_SUNOS_5
---
> /* Ladanyi */
> #if defined (OS_SUNOS_5) || defined (OS_LINUX)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_symscan.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
213c213,214
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined (OS_LINUX)
562c563,564
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined (OS_LINUX)
814c816,817
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined (OS_LINUX)
855c858,859
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined(OS_LINUX)
1204c1208,1209
< #ifdef OS_SUNOS
---
> /* Ladanyi */
> #if defined (OS_SUNOS) || defined (OS_LINUX)
2176,2177c2181,2192
<   demangle_name(name, len, alloc_id, ptr, func,
< 		ao_compiler(fil, FALSE, CT_UNKNOWN));
---
>   /* Dibyendu : when debugging CX executables, demangle_name() does
>    * not make sense - so avoid calling it. I am assuming that CT_UNKNOWN
>    * is not a valid compiler type - and the default. Ideally CX/CG
>    * should get their own type.
>    * ao_compiler() is fooled by setting FI_FOUND_COMPILER flag when
>    * loading a CX executable (see xc_text.c).
>    */
>   Compiler_type ct = ao_compiler(fil, FALSE, CT_UNKNOWN);
>   if (ct == CT_UNKNOWN)
>      *ptr = strdup(name);
>   else
>      demangle_name(name, len, alloc_id, ptr, func, ct);
5137a5153
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ao_text.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28a29,33
> /* Ladanyi */
> #ifdef OS_LINUX
> #include <sys/reg.h>
> #endif
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/cc.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11a12,30
> /* Dibyendu */
> #include <mtrprog/ifdefs.h>
> 
> #include <sys/types.h>
> #include <time.h>
> #include <sys/stat.h>
> #include <stdio.h>
> #include <fcntl.h>
> #include <ctype.h>
> #include <errno.h>
> 
> #if defined (OS_SUNOS_5) && defined (__CLCC__)
> #include <unistd.h>
> #endif
> 
> #include <local/ukcprog.h>
> 
> /* Dibyendu */
> #if 0
20a40,42
> /* Dibyendu */
> #endif
> 
25a48,59
> /* Dibyendu */
> #include "xc_opcodes.h"
> #include "xc_machine.h"
> #include "xc_builtins.h"
> 
> #ifdef BUILTIN_X11
> #include <X11/Xlib.h>
> #include <X11/Xutil.h>
> #include <X11/Xresource.h>
> extern int _Xdebug;
> #endif
> 
301a336
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/xc_text.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
342c342,343
< 	xf = (xc_fidata_t *)alloc(ma->ma_apool, sizeof(xc_fudata_t));
---
> 	/* Dibyendu */
> 	xf = (xc_fidata_t *)alloc(ma->ma_apool, sizeof(xc_fidata_t));
922c923,925
< 			panic("duplicate breakpoint in xc_tswap");
---
> 			/* panic("duplicate breakpoint in xc_tswap"); */
> 			/* Dibyendu */
> 			errf("duplicate breakpoint in xc_tswap");
1117a1121,1128
> 
>                 /* Dibyendu : added to fool ao_compiler() into returning
>                  * CT_UNKNOWN when running UPS over a CX executable.
>                  * This causes demangle_name_2() to do nothing 
>                  * (see ao_symscan.c).
>                  */
>                 filtab[i]->fi_flags |= FI_FOUND_COMPILER;
> 
1346a1358,1363
> 	/* Dibyendu - not sure if this is correct - but seems to work 
>          * for single source CX executables.
>          */
> 	xf->xf_letab = xltab;
> 	xf->xf_letab_size = os->os_letab_count;
> 
1485a1503,1508
> 
> 		/* Dibyendu - ln_fil was not being set causing segmentation
>                  * fault.
>                  */
> 		ln->ln_fil = f->fu_fil;
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/xc_builtins.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106a107,114
> /* Dibyendu */
> #ifdef OS_LINUX
> static FILE* builtin_stdin PROTO((void));
> static FILE* builtin_stderr PROTO((void));
> static FILE* builtin_stdout PROTO((void));
> static int builtin_errno PROTO((void));
> #endif
> 
491a500,527
> 
> /* Dibyendu */
> #ifdef OS_LINUX
> static FILE*
> builtin_stdin(void)
> {
> 	return stdin;
> }
> 
> static FILE*
> builtin_stdout(void)
> {
> 	return stdout;
> }
> 
> static FILE*
> builtin_stderr(void)
> {
> 	return stderr;
> }
> 
> static int
> builtin_errno(void)
> {
> 	return errno;
> }
> #endif
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ci_compile.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1100c1100,1101
< 		if (tx->tx_max_sp & sizeof(stackword_t) != 0)
---
> 		/* Dibyendu */
> 		if ((tx->tx_max_sp % sizeof(stackword_t)) != 0)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/ci_opcodes.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
668c668,670
< 		if (val == switchval)
---
> 		if (val == switchval) {
> 			/* Dibyendu : this was missing */
> 			pc += (short)GETWORD(pc);
669a672
> 		}
675c678,679
< 	return 0;
---
> 	/* Dibyendu : incorrectly returned 0 causing segmentation fault */
> 	return pc;
709c713
< 		pc = get_pc_after_switch_on_chain(pc, (int)ma->ma_sp[0]);
---
> 		pc = get_pc_after_switch_on_chain(pc, (int)(ma->ma_sp[0]));
793c797,799
< 	if (func_index >= 0) {
---
> 	/* Dibyendu : following looks incorrect - see xc_machine.c */
> 	/* if (func_index >= 0) { */
> 	{
802c808,812
< 		er = fcf->cf_funcrefs[-func_index];
---
> 		/* Dibyendu : following looks incorrect - see
> 		 * xc_machine.c.
> 		 */
> 		/* er = fcf->cf_funcrefs[-func_index]; */
> 		er = fcf->cf_funcrefs[func_index];
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/cx.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
213a214,227
> 
> /* Ian Edwards supplied dummy */
> void
> demangle_name_2(name, len, alloc_id, ptr, func, fil)
>          char *name;
>          int len;
>          alloc_pool_t *alloc_id;
>          char **ptr;
>          int func;
>          fil_t *fil;
> {
>       *ptr = strdup (name);
> }
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/cg.c differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
148a149,161
> /* Ian Edwards supplied dummy */
> void
> demangle_name_2(name, len, alloc_id, ptr, func, fil)
>          char *name;
>          int len;
>          alloc_pool_t *alloc_id;
>          char **ptr;
>          int func;
>          fil_t *fil;
> {
>       *ptr = strdup (name);
> }
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/cx_libfuncs.h differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
87a88,95
> /* Dibyendu */
> #if defined(OS_LINUX)
> 	F2(FILE *, builtin_stdin, _stdin_)
> 	F2(FILE *, builtin_stdout, _stdout_)
> 	F2(FILE *, builtin_stderr, _stderr_)
> 	F2(int, builtin_errno, _errno_)
> #endif
> 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
./ups/Makefile differs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23c23
< default_target: ${TARGET}
---
> default_target: ${TARGET} ${CX_BINARY} ${XC_BINARY} ${CG_BINARY}


This archive was generated by hypermail 2.1.4 : Wed Feb 13 2002 - 21:51:32 GMT