Пример #1
0
int parse_single_argument(struct project_cache *pc, int argc, char *argv[])
{
    if ((!strcmp(argv[argc], "-n") || !strcmp(argv[argc], "--name")) &&
        !name_set) {
        set_project_name(&pc->pd, argv[argc + 1]);
        name_set = 1;
        return 0;
    }

    if (!strcmp(argv[argc], "-a") || !strcmp(argv[argc], "--author")) {
        set_project_author(&pc->pd, argv[argc + 1]);
        return 0;
    }

    if (!strcmp(argv[argc], "-d") || !strcmp(argv[argc], "--desc")) {
        struct strbuf temp = STRBUF_INIT;
        strbuf_addstr(&temp, argv[argc + 1]);
        set_project_description(&pc->pd, &temp, 0);
        strbuf_release(&temp);
        return 0;
    }
    if (name_set) return 0;
    fprintf(stderr, "bad arguments\n See " PEG_NAME " init --help for usage");
    exit(0);
}
Пример #2
0
int symbolicate(const char* arch, const char *executable, char *addresses[], int numofaddresses){
    debug("in symbolicate arch: %s executable: %s\n", arch, executable);
    set_project_name(executable);
    debug("about to parse file.");
    struct target_file *tf = parse_file(executable);
    if (tf == NULL){
        debug("parse target file error.");
        return -1;
    }
    debug("parse file finished.");

    struct thin_macho *thin_macho = NULL;
    //TODO performance
    int i = select_thin_macho_by_arch(tf, arch);
    if(i == -1){
        printf("atosl: Can not find macho for architecture: %s.\n", arch);
        return -1;
    }
    thin_macho = tf->thin_machos[i];
    //#ifdef DEBUG
    //    print_all_dwarf2_per_objfile(thin_macho->dwarf2_per_objfile);
    //#endif

    debug("thin_macho->dwarf2_per_objfile: %p.", thin_macho->dwarf2_per_objfile);
    if(thin_macho->dwarf2_per_objfile != NULL){
        debug("about to parse dwarf2 objfile.");
        parse_dwarf2_per_objfile(thin_macho->dwarf2_per_objfile);
        debug("parse dwarf2 objfile finished.");
    }

    #ifdef DEBUG
        print_thin_macho_aranges(thin_macho);
    #endif

    debug("about to invoke numeric_to_symbols.");
    numeric_to_symbols(thin_macho, (const char **)addresses, numofaddresses);
    free_target_file(tf);
    return 0;
}
Пример #3
0
static int parse_arguments(struct project_cache *pc, int argc, char *argv[])
{
    if (argc < 2) die("needed atleast one argument. Use -h for usage.\n");
    for (int i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
            fprintf(stderr, "%s", init_usage);
            exit(0);
        }
    }

    if (argv[1][0] != '-' && !name_set) {
        set_project_name(&pc->pd, argv[1]);
        name_set = 1;
    }

    for (int i = 1; i < argc; i++) parse_single_argument(pc, i, argv);

    if (!cache_valid(pc)) {
        fatal("error specify a project name.\n");
        return -1;
    }
    return 0;
}