Set things up so hush can be build with debug code turned on.

This involved breaking things up into more segments in debug mode, since the code is larger. I also had to remove some unused extern definitions, which were causing link errors when debug code was enabled.

To enable debug code, pass "DEBUG=1" to make or build.gs.
This commit is contained in:
Stephen Heumann 2014-11-06 11:42:17 -06:00
parent a3426d2782
commit 9320c1e704
8 changed files with 45 additions and 57 deletions

View File

@ -17,7 +17,9 @@ COREUTILS_SRC = \
LIBBB_A_SRC = \
libbb/lineedit.c \
libbb/lineedptrhack.c \
libbb/lineedptrhack.c
LIBBB_B_SRC = \
libbb/appletlib.c \
libbb/getopt32.c \
libbb/error.retval.c \
@ -36,7 +38,7 @@ LIBBB_A_SRC = \
libbb/bb.basename.c \
libbb/mempcpy.c
LIBBB_B_SRC = \
LIBBB_C_SRC = \
libbb/perror.msg.c \
libbb/signal.names.c \
libbb/ptrtoglobals.c \
@ -50,7 +52,9 @@ LIBBB_B_SRC = \
libbb/s.gethostname.c \
libbb/safe.poll.c \
libbb/parse.mode.c \
libbb/poll.c \
libbb/poll.c
LIBBB_D_SRC = \
libbb/xfuncs.printf.c \
libbb/xfuncs.c \
libbb/xgetcwd.c \
@ -64,10 +68,24 @@ LIBBB_B_SRC = \
libbb/unicode.c \
libbb/vfork.and.run.c
SRCS = $(MAIN_SRC) $(SHELL_OTHER_SRC) $(COREUTILS_SRC) $(LIBBB_A_SRC) $(LIBBB_B_SRC)
SRCS = $(MAIN_SRC) $(SHELL_OTHER_SRC) $(COREUTILS_SRC) $(LIBBB_A_SRC) \
$(LIBBB_B_SRC) $(LIBBB_C_SRC) $(LIBBB_D_SRC)
OBJS = $(SRCS:.c=.a)
ROOT = $(MAIN_SRC:.c=.root)
SHELL_OTHER_SEG = -SSHELLOTHER
COREUTILS_SEG = -SCOREUTILS_
LIBBB_A_SEG = -SLIBBB_A___
LIBBB_C_SEG = -SLIBBB_C___
# We need more separate segments in debug mode because the code is bigger.
.IF $(DEBUG)
LIBBB_B_SEG = -SLIBBB_B___
LIBBB_D_SEG = -SLIBBB_D___
.ELSE
LIBBB_B_SEG = -SLIBBB_A___
LIBBB_D_SEG = -SLIBBB_C___
.END
INCLUDES = -I include -I shell -I libbb
DEFINES = -Dhush_main=main -DNDEBUG
@ -79,11 +97,12 @@ DEFINES += -DF_SETFD=-1 -DFD_CLOEXEC=-1
# optimize bit 3 set (no stack repair code).
# Optimize bit 6 breaks some standard-compliant varargs code,
# and bits 0, 4, and 5 have known bugs. Disable for now.
OCC_FLAGS = -i -w -a0 -O8
CFLAGS = -i -w -a0 -O8
STACKSIZE = 20480
# Add $(OCC_FLAGS) to CFLAGS on dmake
CFLAGS = $(null, $(OCC_FLAGS))
.IF $(DEBUG)
CFLAGS += -g -DDEBUG
.END
PROG = hush
@ -93,10 +112,12 @@ $(PROG): $(OBJS)
%.a: %.c
$(CC) $(INCLUDES) $(DEFINES) $(CFLAGS) -c $< -o $@ \
$(eq,$<,$(MAIN_SRC) -s$(STACKSIZE) -r) \
$(!eq,$(SHELL_OTHER_SRC:s/$<//),$(SHELL_OTHER_SRC) -SSHELLOTHER) \
$(!eq,$(COREUTILS_SRC:s/$<//),$(COREUTILS_SRC) -SCOREUTILS_) \
$(!eq,$(LIBBB_A_SRC:s/$<//),$(LIBBB_A_SRC) -SLIBBB_A___) \
$(!eq,$(LIBBB_B_SRC:s/$<//),$(LIBBB_B_SRC) -SLIBBB_B___)
$(!eq,$(SHELL_OTHER_SRC:s/$<//),$(SHELL_OTHER_SRC) $(SHELL_OTHER_SEG)) \
$(!eq,$(COREUTILS_SRC:s/$<//),$(COREUTILS_SRC) $(COREUTILS_SEG)) \
$(!eq,$(LIBBB_A_SRC:s/$<//),$(LIBBB_A_SRC) $(LIBBB_A_SEG)) \
$(!eq,$(LIBBB_B_SRC:s/$<//),$(LIBBB_B_SRC) $(LIBBB_B_SEG)) \
$(!eq,$(LIBBB_C_SRC:s/$<//),$(LIBBB_C_SRC) $(LIBBB_C_SEG)) \
$(!eq,$(LIBBB_D_SRC:s/$<//),$(LIBBB_D_SRC) $(LIBBB_D_SEG))
.PHONY: clean
clean:

View File

@ -1 +1 @@
chtyp -l cc include/*.h coreutils/*.c libbb/*.c shell/*.c shell/*.h; make -i
chtyp -l cc include/*.h coreutils/*.c libbb/*.c shell/*.c shell/*.h; make -i $1

View File

@ -13,19 +13,6 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
/* Defined in appletlib.c (by including generated applet_tables.h) */
/* Keep in sync with applets/applet_tables.c! */
extern const char applet_names[] ALIGN1;
extern int (*const applet_main[])(int argc, char **argv);
extern const uint16_t applet_nameofs[];
extern const uint8_t applet_install_loc[] ALIGN1;
#if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS
# define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff))
#else
# define APPLET_NAME(i) (applet_names + applet_nameofs[i])
#endif
#if ENABLE_FEATURE_PREFER_APPLETS
# define APPLET_IS_NOFORK(i) (applet_nameofs[i] & (1 << 12))
# define APPLET_IS_NOEXEC(i) (applet_nameofs[i] & (1 << 13))
@ -38,14 +25,6 @@ extern const uint8_t applet_install_loc[] ALIGN1;
# define APPLET_SUID(i) ((applet_nameofs[i] >> 14) & 0x3)
#endif
#if ENABLE_FEATURE_INSTALLER
#define APPLET_INSTALL_LOC(i) ({ \
unsigned v = (i); \
if (v & 1) v = applet_install_loc[v/2] >> 4; \
else v = applet_install_loc[v/2] & 0xf; \
v; })
#endif
/* Length of these names has effect on size of libbusybox
* and "individual" binaries. Keep them short.

View File

@ -16,7 +16,6 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
#if defined __UCLIBC__ /* TODO: and glibc? */
@ -948,12 +947,10 @@ enum {
DAEMON_DOUBLE_FORK = 16 /* double fork to avoid controlling tty */
};
#if BB_MMU
enum { re_execed = 0 };
# define fork_or_rexec(argv) xfork()
# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
# define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus)
#else
extern bool re_execed;
/* Note: re_exec() and fork_or_rexec() do argv[0][0] |= 0x80 on NOMMU!
* _Parent_ needs to undo it if it doesn't want to have argv[0] mangled.
*/
@ -1008,25 +1005,11 @@ llist_t *llist_find_str(llist_t *first, const char *str) FAST_FUNC;
* llist_t *llist_add_to(llist_t *old_head, void *data)
* etc does not result in smaller code... */
/* start_stop_daemon and udhcpc are special - they want
* to create pidfiles regardless of FEATURE_PIDFILE */
#if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE)
/* True only if we created pidfile which is *file*, not /dev/null etc */
extern smallint wrote_pidfile;
void write_pidfile(const char *path) FAST_FUNC;
#define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0)
#else
enum { wrote_pidfile = 0 };
#define write_pidfile(path) ((void)0)
#define remove_pidfile(path) ((void)0)
#endif
enum {
LOGMODE_NONE = 0,
LOGMODE_STDIO = (1 << 0)
};
extern const char *msg_eol;
extern smallint syslog_level;
extern smallint logmode;
extern int die_sleep;
extern uint8_t xfunc_error_retval;
@ -1103,7 +1086,6 @@ struct hwtype {
int FAST_FUNC (*activate)(int fd);
int suppress_null_addr;
};
extern smallint interface_opt_a;
int display_interfaces(char *ifname) FAST_FUNC;
int in_ether(const char *bufp, struct sockaddr *sap) FAST_FUNC;
#if ENABLE_FEATURE_HWIB
@ -1488,7 +1470,6 @@ unsigned get_cpu_count(void) FAST_FUNC;
char *percent_decode_in_place(char *str, int strict) FAST_FUNC;
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
@ -1521,8 +1502,6 @@ void bb_progress_update(bb_progress_t *p,
uoff_t totalsize) FAST_FUNC;
extern const char *applet_name;
/* Some older linkers don't perform string merging, we used to have common strings
* as global arrays to do it by hand. But:
* (1) newer linkers do it themselves,

View File

@ -17,6 +17,8 @@ smallint syslog_level = LOG_ERR;
smallint logmode = LOGMODE_STDIO;
const char *msg_eol = "\n";
extern const char *applet_name;
void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
{
char *msg, *msg1;

View File

@ -11,8 +11,6 @@
* unsupported: GLOB_BRACE GLOB_ALTDIRFUNC GLOB_MAGCHAR
*/
#define DEBUG(x)
#include "glob.h"
#include <stdlib.h>

View File

@ -3417,6 +3417,10 @@ static int done_word(o_string *word, struct parse_context *ctx)
}
#if defined(__ORCAC__) && defined(DEBUG)
segment "HUSH_B____";
#endif
/* Peek ahead in the input to find out if we have a "&n" construct,
* as in "2>&1", that represents duplicating a file descriptor.
* Return:
@ -5638,7 +5642,7 @@ static char **expand_assignments(char **argv, int count)
#ifdef __ORCAC__
segment "HUSH_B____";
segment "HUSH_C____";
#endif
static void switch_off_special_sigs(unsigned mask)
@ -7502,6 +7506,10 @@ static void forked_child(void *args_struct) {
#endif
#if defined(__ORCAC__) && defined(DEBUG)
segment "HUSH_D____";
#endif
/* NB: called by pseudo_exec, and therefore must not modify any
* global data until exec/_exit (we can be a child after vfork!) */
static int run_list(struct pipe *pi)

1
texttogs Normal file
View File

@ -0,0 +1 @@
udl -g include/*.h coreutils/*.c libbb/*.c shell/*.c shell/*.h Makefile