static void load_ptrace_map_info_data(pid_t pid, map_info_t* mi) { if (mi->is_executable && mi->is_readable) { uint32_t elf_magic; if (try_get_word_ptrace(pid, mi->start, &elf_magic) && elf_magic == ELF_MAGIC) { map_info_data_t* data = (map_info_data_t*)calloc(1, sizeof(map_info_data_t)); if (data) { mi->data = data; if (mi->name[0]) { data->symbol_table = load_symbol_table(mi->name); } #ifdef CORKSCREW_HAVE_ARCH load_ptrace_map_info_data_arch(pid, mi, data); #endif } } } }
int main(int argc, char **argv) { iENTER; //FSTREAM_READER_STATE *preader_state = NULL; //FSTREAM_WRITER_STATE *pwriter_state = NULL; ION_STREAM *output_stream = NULL; ION_STREAM *input_stream = NULL; hWRITER hwriter = 0; hREADER hreader = 0; ION_STRING temp; char *name = NULL; ION_TYPE t = (ION_TYPE)999; int32_t symbol_table_count = 0; int ii, non_argc = 0; char **non_argv = NULL; ION_STRING_INIT(&temp); // read the command line for any instruction the caller might have non_argv = (char**)malloc(argc * sizeof(char*)); process_args(argc, argv, non_argv, &non_argc); if (g_print_help) SUCCEED(); // clear the option structs and set them appropriately memset(&g_reader_options, 0, sizeof(g_reader_options)); memset(&g_writer_options, 0, sizeof(g_writer_options)); g_writer_options.pretty_print = TRUE; // set up our debug options if (g_dump_args) dump_arg_globals(); if (g_timer) { start_timing(); } // read in the catalog, if there is one if (g_catalogs) { CHECK( load_catalog_list(&g_hcatalog), "load a catalog file" ); CHECK(ion_catalog_get_symbol_table_count(g_hcatalog, &symbol_table_count), "get the symbol table count from the loaded catalog"); fprintf(stderr, "Catalog loaded %d symbol tables\n", symbol_table_count); } else { CHECK( ion_catalog_open( &g_hcatalog ), "open empty catalog" ); } g_reader_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - HOW SHOULD WE HANDLE THIS? - either the options g_writer_options.pcatalog = (ION_CATALOG *)g_hcatalog; // HACK - TODO - should have an hcatalog or we need a h to p fn // if we're updating an existing catalog load it if (g_update_symtab) { // load specified symbol table CHECK( load_symbol_table(&g_hsymtab, g_update_symtab), "load symbol table to update"); } else { // othwerwise we need to init a symbol table to update CHECK( initialize_new_symbol_table(&g_hsymtab), "initialize a new (empty) symbol table to fill" ); } // open the output stream writer attached to stdout // TODO: allow caller to specify the output file on the command line CHECK( ion_stream_open_stdout( &output_stream ), "ion stream open stdout failed"); CHECK( ion_writer_open( &hwriter, output_stream, &g_writer_options), "ion writer open failed"); //CHECK( ion_writer_open_fstream(&pwriter_state, stdout, &g_writer_options), "writer open failed"); // now, do we process from stdin or from file names on the command line if (non_argc > 0) { // file names for (ii=0; ii<non_argc; ii++) { // open our input and output streams (reader and writer) CHECK( process_filename(non_argv[ii], &g_reader_options), "process filename failed" ); } } else { // from stdin // open our input and output streams (reader and writer) CHECK( ion_stream_open_stdin( &input_stream ), "open stdin as an ION_STREAM failed"); CHECK( ion_reader_open(&hreader, input_stream, &g_reader_options), "open stdin as an ion reader failed"); //CHECK( ion_reader_open_fstream(&preader_state, stdin, &g_reader_options), "reader open stdin failed"); CHECKREADER( process_input_reader(hreader), "process stdin", hreader ); CHECK( ion_reader_close( hreader ), "closing the ion reader"); CHECK( ion_stream_close( input_stream), "closing the input stream"); // CHECK( ion_reader_close_fstream( preader_state ), "closing the reader"); } // if we're emitting a symbol table we need to actually output the // table now (we only collected the symbols from the input sources // during the pass above CHECK( symbol_table_write( hwriter ), "emit the new symbol table we've built up" ); // close up //CHECK( ion_writer_close_fstream( pwriter_state ), "closing the writer"); CHECK( ion_writer_close( hwriter ), "closing the ion writer"); CHECK( ion_stream_close( output_stream ), "closing the ion output stream"); if (g_hsymtab) CHECK(ion_symbol_table_close(g_hsymtab), "closing the temp symbol table"); if (g_hcatalog) CHECK(ion_catalog_close(g_hcatalog), "closing the catalog"); SUCCEED(); fail:// this is iRETURN expanded so I can set a break point on it if (g_debug) { fprintf(stderr, "\nionsymbols finished, returning err [%d] = \"%s\", %d\n", err, ion_error_to_str(err), (intptr_t)t); } if (g_timer) { stop_timing(); } if (non_argv) free(non_argv); return err; }