Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7e7ad462ff71adefb7db0ad016a77516866b4971 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 * You may elect to redistribute this code under either of these licenses.
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/

/*
 * TCF service line Numbers - ELF version.
 *
 * The service associates locations in the source files with the corresponding
 * machine instruction addresses in the executable object.
 */

#include <tcf/config.h>

#if SERVICE_LineNumbers && !ENABLE_LineNumbersProxy && ENABLE_LineNumbersMux

#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include <tcf/framework/myalloc.h>
#include <tcf/services/linenumbers.h>
#include <tcf/services/linenumbers_mux.h>

static LineNumbersReader ** readers = NULL;
static unsigned reader_count = 0;
static unsigned max_reader_count = 0;

#if ENABLE_ELF
extern void elf_ini_line_numbers_lib(void);
#endif
#if defined(_WIN32)
extern void win32_ini_line_numbers_lib(void);
#endif

int line_to_address(Context * ctx, char * file_name, int line, int column,
                    LineNumbersCallBack * client, void * args) {
    unsigned i;
    for (i = 0; i < reader_count; i++) {
        if (readers[i]->line_to_address(ctx, file_name, line, column, client, args) != 0) {
            return -1;
        }
    }
    return 0;
}

int address_to_line(Context * ctx, ContextAddress addr0, ContextAddress addr1,
        LineNumbersCallBack * client, void * args) {
    unsigned i;
    for (i = 0; i < reader_count; i++) {
        if (readers[i]->address_to_line(ctx, addr0, addr1, client, args) != 0) {
            return -1;
        }
    }
    return 0;
}

int add_line_numbers_reader(LineNumbersReader * reader) {
    if (reader_count >= max_reader_count) {
        max_reader_count += 2;
        readers = (LineNumbersReader **)loc_realloc(readers, max_reader_count * sizeof(reader));
    }
    readers[reader_count] = reader;
    reader->reader_index = reader_count;
    reader_count++;
    return 0;
}

void ini_line_numbers_lib(void) {
#if ENABLE_ELF
    elf_reader_ini_line_numbers_lib();
#endif
#if ENABLE_PE
    win32_reader_ini_line_numbers_lib();
#endif
}

#endif /* SERVICE_LineNumbers && !ENABLE_LineNumbersProxy && ENABLE_ELF */

Back to the top