Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09e71378 authored by Ben Cheng's avatar Ben Cheng
Browse files

Print code around PC and LR in the inline log.

8 more lines should provide more crucial information in weird cases.
parent 3afe20b0
Loading
Loading
Loading
Loading
+95 −105
Original line number Diff line number Diff line
@@ -48,8 +48,6 @@ extern int unwind_backtrace_with_ptrace(int tfd, pid_t pid, mapinfo *map,
                                        int *frame0_pc_sane,
                                        bool at_fault);

static char **process_name_ptr;

static int logsocket = -1;

#define ANDROID_LOG_INFO 4
@@ -128,6 +126,7 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
    struct pt_regs r;
    int sp_depth;
    bool only_in_tombstone = !at_fault;
    char code_buffer[80];

    if(ptrace(PTRACE_GETREGS, pid, 0, &r)) return;
    sp = r.ARM_sp;
@@ -140,26 +139,53 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
        pc = r.ARM_lr;
    }

    _LOG(tfd, true, "code%s:\n", frame0_pc_sane ? "" : " (around frame #01)");
    _LOG(tfd, only_in_tombstone,
         "\ncode around %s:\n", frame0_pc_sane ? "pc" : "lr");

    end = p = pc & ~3;
    p -= 16;
    end += 16;

    /* Dump the code as:
     *  PC         contents
    /* Dump the code around PC as:
     *  addr       contents
     *  00008d34   fffffcd0 4c0eb530 b0934a0e 1c05447c
     *  00008d44   f7ff18a0 490ced94 68035860 d0012b00
     */
    while (p <= end) {
        int i;

        _LOG(tfd, true, " %08x  ", p);
        sprintf(code_buffer, "%08x ", p);
        for (i = 0; i < 4; i++) {
            data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
            _LOG(tfd, true, " %08x", data);
            sprintf(code_buffer + strlen(code_buffer), "%08x ", data);
            p += 4;
        }
        _LOG(tfd, true, "\n", p);
        _LOG(tfd, only_in_tombstone, "%s\n", code_buffer);
    }

    if (frame0_pc_sane) {
        _LOG(tfd, only_in_tombstone, "\ncode around lr:\n");

        end = p = r.ARM_lr & ~3;
        p -= 16;
        end += 16;

        /* Dump the code around LR as:
         *  addr       contents
         *  00008d34   fffffcd0 4c0eb530 b0934a0e 1c05447c
         *  00008d44   f7ff18a0 490ced94 68035860 d0012b00
         */
        while (p <= end) {
            int i;

            sprintf(code_buffer, "%08x ", p);
            for (i = 0; i < 4; i++) {
                data = ptrace(PTRACE_PEEKTEXT, pid, (void*)p, NULL);
                sprintf(code_buffer + strlen(code_buffer), "%08x ", data);
                p += 4;
            }
            _LOG(tfd, only_in_tombstone, "%s\n", code_buffer);
        }
    }

    p = sp - 64;
@@ -177,7 +203,7 @@ void dump_stack_and_code(int tfd, int pid, mapinfo *map,
        end += 0xff;
    }

    _LOG(tfd, only_in_tombstone, "stack:\n");
    _LOG(tfd, only_in_tombstone, "\nstack:\n");

    /* If the crash is due to PC == 0, there will be two frames that
     * have identical SP value.
@@ -330,7 +356,7 @@ static void parse_exidx_info(mapinfo *milist, pid_t pid)
            ptr = (Elf32_Phdr *) (mi->start + ehdr.e_phoff);
            for (i = 0; i < ehdr.e_phnum; i++) {
                /* Parse the program header */
                get_remote_struct(pid, (void *) ptr+i, &phdr, 
                get_remote_struct(pid, (char *) ptr+i, &phdr,
                                  sizeof(Elf32_Phdr));
                /* Found a EXIDX segment? */
                if (phdr.p_type == PT_ARM_EXIDX) {
@@ -401,40 +427,6 @@ void dump_crash_report(int tfd, unsigned pid, unsigned tid, bool at_fault)
    }
}

/* FIXME: unused: use it or lose it*/
#if 0
static
void start_gdbserver_vs(int pid, int port)
{
    pid_t p;
    char *args[5];
    char commspec[16];
    char pidspec[16];
    
    p = fork();
    if(p < 0) {
        LOG("could not fork()\n");
        return;
    }

    if(p == 0) {
        sprintf(commspec, ":%d", port);
        sprintf(pidspec, "%d", pid);
        args[0] = "/system/bin/gdbserver";
        args[1] = commspec;
        args[2] = "--attach";
        args[3] = pidspec;
        args[4] = 0;
        exit(execv(args[0], args));
    } else {
        LOG("gdbserver pid=%d port=%d targetpid=%d\n",
            p, port, pid);

        sleep(5);
    }
}
#endif

#define MAX_TOMBSTONES	10

#define typecheck(x,y) {    \
@@ -807,13 +799,11 @@ done:
    if(fd != -1) close(fd);
}

int main(int argc, char **argv)
int main()
{
    int s;
    struct sigaction act;

    process_name_ptr = argv;
    
    logsocket = socket_local_client("logd",
            ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM);
    if(logsocket < 0) {