int main( int argc, char **argv ) { int ret; if( getuid() ) { printf("You must be root to run the MOL debugger\n"); return 1; } mregs = &sv.mregs; res_manager_init(0, argc, argv ); atexit( res_manager_cleanup ); /* Initialize socket and connect to MOL */ sv.fd = -1; do_connect(); symbols_init(); monitor_init(); cmdline_init(); install_monitor_cmds(); printm("Mac-on-Linux debugger %s, ", MOL_RELEASE); printm("(C) 2001 Samuel Rydh <*****@*****.**>\n"); atexit(exit_hook); for( ;; ) { if( (ret = mon_debugger()) == kDbgExit ) break; send_dgram1( sv.fd, kMDG_debug_action, ret ); } send_dgram( sv.fd, kMDG_disconnect ); return 0; }
int main(int argc, char **argv) { int i; context_t ctx; char *entry_hook_line = "{exec {print-str ' entry:'} [var 0 0]" "\n {while <is-le [var 0] 10>" "\n {exec" "\n {print-char 32}" "\n {print-hex0 [reg [var 0]]}" "\n {if <is-null [reg [var 0]]>" "\n (break)" "\n }" "\n [var 0 (add [var 0] 1)]" "\n }" "\n }" "\n (print-char 10)" "\n}"; char *exit_hook_line = "{exec {print-str ' exit:'} [var 0 0]" "\n {while <is-le [var 0] 10>" "\n {exec {print-str ' '} (print-hex0 [reg [var 0]]) [var 0 (add [var 0] 1)]}" "\n }" "\n (print-char 10)" "\n}"; hook_p h; if (strings_init(STRING_BUFF) || atoms_init(MAX_ATOMS) || symbols_init(MAX_SYMBOLS) || ringbuf_init(4096) || hooks_init(4, NULL, NULL)) return -1; if (argc > 1) entry_hook_line = argv[1]; if (argc > 2) exit_hook_line = argv[2]; h = hook_install((uint_t)funnn, entry_hook_line, exit_hook_line, NULL, ringbuf_dump, splinter_test_mode); if (!h) { fprintf(stderr, "%s", splinter_error_get()); return -1; } h->enabled = 1; memset(&ctx, 0, sizeof(ctx)); for(i = 0; i < 1; i++) { context_call(&h->entry_chain, h, &ctx); context_call(&h->exit_chain, h, &ctx); context_close(h, &ctx); } dump_ringbuffer(); return 0; }
void dwarf_init(dwarf_t* dwarf, pass_opt_t* opt, LLVMBuilderRef builder, LLVMTargetDataRef layout, LLVMModuleRef module) { dwarf->opt = opt; dwarf->target_data = layout; dwarf->has_source = false; symbols_init(&dwarf->symbols, builder, module, opt->release); symbols_unspecified(dwarf->symbols, stringtab("$object")); }
ComplexQuery pComplexQuery(FILE *inp) { symbols_init(); initialize_lexer(inp); if (yyparse()) { /* Failure */ return 0; } else { /* Success */ return YY_RESULT_ComplexQuery_; } }
int symbols_getId(char* name){ int i; Symbol *tmp; if(!symbols_size) symbols_init(); for(i=0;i<symbols_count;i++) if(strcmp(name, symbols[i].name)==0) return i; if(symbols_size == symbols_count){ symbols_size*=2; tmp = (Symbol*) malloc(symbols_size * sizeof(Symbol*)); for(i=0;i<symbols_count;i++) tmp[i] = symbols[i]; free(symbols); symbols = tmp; } i = symbols_count++; symbols[i].name = strdup(name); symbols[i].zapyt = NULL; return symbols_count-1; }
void assembler_init() { struct asm_context_t *ctx; app.asmcontext = malloc(sizeof(struct asm_context_t)); if (!app.asmcontext) { debug_emsg("Can not allocate memory"); app_close(APP_EXITCODE_ERROR); } ctx = app.asmcontext; ctx->pass = 0; ctx->dbendian = DB_ENDIAN_BIG; tokens_init(&ctx->tokens); symbols_init(&ctx->symbols); sections_init(&ctx->sections); relocations_init(&ctx->relocations); ctx->section = section_select(&ctx->sections, "text"); }
int main(int argc, char *argv[]) { FILE *out; FILE *dbg = NULL; //FILE *list = NULL; int i; int format = FORMAT_HEX; int create_list = 0; char *infile = NULL, *outfile = NULL; struct _asm_context asm_context; int error_flag=0; puts(credits); if (argc < 2) { printf("Usage: naken_asm [options] <infile>\n" " -o <outfile>\n" " -h [output hex file]\n" #ifndef DISABLE_ELF " -e [output elf file]\n" #endif " -b [output binary file]\n" " -s [output srec file]\n" " -l [create .lst listing file]\n" " -I [add to include path]\n" " -q Quiet (only output errors)\n" "\n"); exit(0); } memset(&asm_context, 0, sizeof(asm_context)); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-o") == 0) { outfile = argv[++i]; } else if (strcmp(argv[i], "-h") == 0) { format = FORMAT_HEX; } else if (strcmp(argv[i], "-b") == 0) { format = FORMAT_BIN; } else if (strcmp(argv[i], "-s") == 0) { format = FORMAT_SREC; } #ifndef DISABLE_ELF else if (strcmp(argv[i], "-e") == 0) { format = FORMAT_ELF; } #endif #if 0 else if (strcmp(argv[i], "-d") == 0) { asm_context.debug_file = 1; } #endif else if (strcmp(argv[i], "-l") == 0) { create_list = 1; } else if (strncmp(argv[i], "-I", 2) == 0) { char *s = argv[i]; if (s[2] == 0) { if (add_to_include_path(&asm_context, argv[++i]) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } } else { if (add_to_include_path(&asm_context, s+2) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } } } else if (strcmp(argv[i], "-q") == 0) { asm_context.quiet_output = 1; } else { if (infile != NULL) { printf("Error: Cannot use %s as input file since %s was already chosen.\n", argv[1], infile); exit(1); } infile = argv[i]; } } if (infile == NULL) { printf("No input file specified.\n"); exit(1); } if (outfile == NULL) { switch(format) { case FORMAT_HEX: outfile = "out.hex"; break; case FORMAT_BIN: outfile = "out.bin"; break; case FORMAT_ELF: outfile = "out.elf"; break; case FORMAT_SREC: outfile = "out.srec"; break; default: outfile = "out.err"; break; } } #ifdef INCLUDE_PATH if (add_to_include_path(&asm_context, INCLUDE_PATH) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } #endif if (tokens_open_file(&asm_context, infile) != 0) { printf("Couldn't open %s for reading.\n", infile); exit(1); } out = fopen(outfile, "wb"); if (out == NULL) { printf("Couldn't open %s for writing.\n", outfile); exit(1); } if (asm_context.quiet_output == 0) { printf(" Input file: %s\n", infile); printf("Output file: %s\n", outfile); } #if 0 if (asm_context.debug_file == 1) { char filename[1024]; strcpy(filename, outfile); new_extension(filename, "ndbg", 1024); dbg = fopen(filename,"wb"); if (dbg == NULL) { printf("Couldn't open %s for writing.\n",filename); exit(1); } printf(" Debug file: %s\n",filename); fprintf(dbg, "%s\n", infile); } #endif if (create_list == 1) { char filename[1024]; strcpy(filename, outfile); new_extension(filename, "lst", 1024); asm_context.list = fopen(filename, "wb"); if (asm_context.list == NULL) { printf("Couldn't open %s for writing.\n", filename); exit(1); } if (asm_context.quiet_output == 0) { printf(" List file: %s\n", filename); } } if (asm_context.quiet_output == 0) { printf("\nPass 1...\n"); } symbols_init(&asm_context.symbols); macros_init(&asm_context.macros); asm_context.pass = 1; assemble_init(&asm_context); error_flag = assemble(&asm_context); if (error_flag != 0) { printf("** Errors... bailing out\n"); unlink(outfile); } else { symbols_lock(&asm_context.symbols); // macros_lock(&asm_context.defines_heap); if (asm_context.quiet_output == 0) { printf("Pass 2...\n"); } asm_context.pass = 2; assemble_init(&asm_context); error_flag = assemble(&asm_context); if (format == FORMAT_HEX) { write_hex(&asm_context.memory, out); } else if (format == FORMAT_BIN) { write_bin(&asm_context.memory, out); } else if (format == FORMAT_SREC) { write_srec(&asm_context.memory, out); } #ifndef DISABLE_ELF else if (format == FORMAT_ELF) { write_elf(&asm_context.memory, out, &asm_context.symbols, asm_context.filename, asm_context.cpu_type); } #endif if (dbg != NULL) { for (i = 0; i < asm_context.memory.size; i++) { int debug_line = memory_debug_line(&asm_context, i); putc(debug_line >> 8, dbg); putc(debug_line & 0xff, dbg); } fclose(dbg); } } fclose(out); if (create_list == 1) { int ch = 0; char str[17]; int ptr = 0; fprintf(asm_context.list, "data sections:"); for (i = asm_context.memory.low_address; i <= asm_context.memory.high_address; i++) { if (memory_debug_line(&asm_context, i) == -2) { if (ch == 0) { if (ptr != 0) { output_hex_text(asm_context.list, str, ptr); } fprintf(asm_context.list, "\n%04x:", i/asm_context.bytes_per_address); ptr = 0; } unsigned char data = memory_read(&asm_context, i); fprintf(asm_context.list, " %02x", data); if (data >= ' ' && data <= 120) { str[ptr++] = data; } else { str[ptr++] = '.'; } ch++; if (ch == 16) { ch = 0; } } else { output_hex_text(asm_context.list, str, ptr); ch = 0; ptr = 0; } } output_hex_text(asm_context.list, str, ptr); fprintf(asm_context.list, "\n\n"); assemble_print_info(&asm_context, asm_context.list); } assemble_print_info(&asm_context, stdout); //symbols_free(&asm_context.symbols); //macros_free(&asm_context.macros); if (asm_context.list != NULL) { fclose(asm_context.list); } fclose(asm_context.in); if (error_flag != 0) { printf("*** Failed ***\n\n"); unlink(outfile); } //memory_free(&asm_context.memory); assemble_free(&asm_context); if (error_flag != 0) { return -1; } return 0; }
int main (int argc, char *argv[]) { char symtab; char symbol; char dest[8]; char description[50]; symbols_init (); symbols_from_dest_or_src ('T', "W1ABC", "GPSC43", &symtab, &symbol); if (symtab != '/' || symbol != 'K') dw_printf ("ERROR 1-1\n"); symbols_from_dest_or_src ('T', "W1ABC", "GPSE87", &symtab, &symbol); if (symtab != '\\' || symbol != 'w') dw_printf ("ERROR 1-2\n"); symbols_from_dest_or_src ('T', "W1ABC", "SPCBL", &symtab, &symbol); if (symtab != '/' || symbol != '+') dw_printf ("ERROR 1-3\n"); symbols_from_dest_or_src ('T', "W1ABC", "SYMST", &symtab, &symbol); if (symtab != '\\' || symbol != 't') dw_printf ("ERROR 1-4\n"); symbols_from_dest_or_src ('T', "W1ABC", "GPSOD9", &symtab, &symbol); if (symtab != '9' || symbol != '#') dw_printf ("ERROR 1-5\n"); symbols_from_dest_or_src ('T', "W1ABC-14", "XXXXXX", &symtab, &symbol); if (symtab != '/' || symbol != 'k') dw_printf ("ERROR 1-6\n"); symbols_from_dest_or_src ('T', "W1ABC", "GPS???", &symtab, &symbol); /* Outputs are left alone if symbol can't be determined. */ if (symtab != '/' || symbol != 'k') dw_printf ("ERROR 1-7\n"); symbols_into_dest ('/', 'K', dest); if (strcmp(dest, "GPSC43") != 0) dw_printf ("ERROR 2-1\n"); symbols_into_dest ('\\', 'w', dest); if (strcmp(dest, "GPSE87") != 0) dw_printf ("ERROR 2-2\n"); symbols_into_dest ('3', 'A', dest); if (strcmp(dest, "GPSAA3") != 0) dw_printf ("ERROR 2-3\n"); // Expect to see this: // Could not convert symbol " A" to GPSxyz destination format. // Could not convert symbol "/ " to GPSxyz destination format. symbols_into_dest (' ', 'A', dest); if (strcmp(dest, "GPS???") != 0) dw_printf ("ERROR 2-4\n"); symbols_into_dest ('/', ' ', dest); if (strcmp(dest, "GPS???") != 0) dw_printf ("ERROR 2-5\n"); symbols_get_description ('J', 's', description); if (strcmp(description, "Jet Ski") != 0) dw_printf ("ERROR 3-1\n"); symbols_get_description ('/', 'O', description); if (strcmp(description, "BALLOON") != 0) dw_printf ("ERROR 3-2\n"); symbols_get_description ('\\', 'T', description); if (strcmp(description, "Thunderstorm") != 0) dw_printf ("ERROR 3-3\n"); symbols_get_description ('5', 'T', description); if (strcmp(description, "Thunderstorm w/overlay 5") != 0) dw_printf ("ERROR 3-4\n"); // Expect to see this: // Symbol table identifier is not '/' (primary), '\' (alternate), or valid overlay character. symbols_get_description (' ', 'T', description); if (strcmp(description, "--no-symbol--") != 0) dw_printf ("ERROR 3-5\n"); symbols_get_description ('/', ' ', description); if (strcmp(description, "--no-symbol--") != 0) dw_printf ("ERROR 3-6\n"); symbols_code_from_description ('5', "girl scouts", &symtab, &symbol); if (symtab != '5' || symbol != ',') dw_printf ("ERROR 4-1\n"); symbols_code_from_description (' ', "scouts", &symtab, &symbol); if (symtab != '/' || symbol != ',') dw_printf ("ERROR 4-2\n"); symbols_code_from_description (' ', "girl scouts", &symtab, &symbol); if (symtab != '\\' || symbol != ',') dw_printf ("ERROR 4-3\n"); symbols_code_from_description (' ', "jet ski", &symtab, &symbol); if (symtab != 'J' || symbol != 's') dw_printf ("ERROR 4-4\n"); symbols_code_from_description (' ', "girl scouts", &symtab, &symbol); if (symtab != '\\' || symbol != ',') dw_printf ("ERROR 4-5\n"); symbols_code_from_description (' ', "yen", &symtab, &symbol); if (symtab != 'Y' || symbol != '$') dw_printf ("ERROR 4-6\n"); symbols_code_from_description (' ', "taco bell", &symtab, &symbol); if (symtab != 'T' || symbol != 'R') dw_printf ("ERROR 4-7\n"); } /* end main */
int symbols_code_from_description (char overlay, char *description, char *symtab, char *symbol) { int j; symbols_init(); /* * If user specified a particular overlay (i.e. for config file BEACON), * first try the alternate symbol table. * If that fails should we give up or ignore the overlay and keep trying? */ if (isupper(overlay) || isdigit(overlay)) { for (j=0; j<SYMTAB_SIZE; j++) { if (strcasestr(alternate_symtab[j].description, description) != NULL) { *symtab = overlay; *symbol = j + ' '; return (1); } } /* If that fails should we give up or ignore the overlay and keep trying? */ } /* * Search primary table. */ for (j=0; j<SYMTAB_SIZE; j++) { if (strcasestr(primary_symtab[j].description, description) != NULL) { *symtab = '/'; *symbol = j + ' '; return (1); } } /* * Search alternate table. */ for (j=0; j<SYMTAB_SIZE; j++) { if (strcasestr(alternate_symtab[j].description, description) != NULL) { *symtab = '\\'; *symbol = j + ' '; return (1); } } /* * Finally, the "new" symbols. * Probably want this last so get get the most standard and * generic for queries such as "house" or ... */ for (j=0; j<new_sym_len; j++) { if (strcasestr(new_sym_ptr[j].description, description) != NULL) { *symtab = new_sym_ptr[j].overlay; *symbol = new_sym_ptr[j].symbol; return (1); } } /* * Default to something generic like house. * Caller is responsible for issuing error message. */ *symtab = '/'; *symbol = '-'; return (0); } /* end symbols_code_from_description */
void symbols_get_description (char symtab, char symbol, char *description, size_t desc_size) { char tmp2[2]; int j; symbols_init(); // The symbol table identifier should be // / for symbol from primary table // \ for symbol from alternate table // 0-9,A-Z for alternate symbol table with overlay character if (symtab != '/' && symtab != '\\' && ! isdigit(symtab) && ! isupper(symtab)) { text_color_set(DW_COLOR_ERROR); dw_printf ("Symbol table identifier is not '/' (primary), '\\' (alternate), or valid overlay character.\n"); /* Possibilities: */ /* Select primary table and keep going, or */ /* report no symbol. It IS an error. */ /* We do the latter. */ symbol = ' '; strlcpy (description, primary_symtab[symbol-' '].description, desc_size); return; } // Bounds check before using symbol as index into table. if (symbol < ' ' || symbol > '~') { text_color_set(DW_COLOR_ERROR); dw_printf ("Symbol code is not a printable character.\n"); symbol = ' '; /* Avoid subscript out of bounds. */ } // First try to match with the "new" symbols. for (j=0; j<new_sym_len; j++) { if (symtab == new_sym_ptr[j].overlay && symbol == new_sym_ptr[j].symbol) { strlcpy (description, new_sym_ptr[j].description, desc_size); return; } } // Otherwise use the original symbol tables. if (symtab == '/') { strlcpy (description, primary_symtab[symbol-' '].description, desc_size); } else { strlcpy (description, alternate_symtab[symbol-' '].description, desc_size); if (symtab != '\\') { strlcat (description, " w/overlay ", desc_size); tmp2[0] = symtab; tmp2[1] = '\0'; strlcat (description, tmp2, desc_size); } } } /* end symbols_get_description */