~ubuntu-branches/ubuntu/precise/dwarves-dfsg/precise

« back to all changes in this revision

Viewing changes to syscse.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Girard
  • Date: 2011-05-02 19:34:31 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20110502193431-xd7eeb4sarnmyd7e
Tags: 1.9-1
* Acknowledge 1.3-1.1 NMU (thanks to Michael Banck) and resynch with
  Ubuntu release (thanks Bhavani Shankar).
* New upstream release:
  - patch from 1.3-1.1ubuntu1 no longer needed.
  - new manpage for pahole.
  - new program scncopy to copy ELF sections.
  - fixes crash when encountering a pointer in a struct. Closes: #513573.
  - recognizes C++ classes. Closes: #621530.
  - no longer FTBFS with gcc 4.6. Closes: #625158.
* Remove libebl detection and use. Closes: #534529.
* debian/control:
  - bump debhelper level to 7.
  - add Vcs-Git: and Vcs-Browser:
  - bump Standards-Version: to 3.9.2.
  - add zlib1g-dev build dependency.
* debian/copyright: add missing copyright holders.
* debian/rules:
  - allow to be compiled twice in a row.
  - ensure package building aborts if a program is not installed.
  - use dh_prep instead of dh_clean -k.
* debian/dwarves.install:
  - include syscse. Closes: #517180.
  - add ctracer. See README.ctracer for information on how to use it.
* Switch to dpkg-source 3.0 (quilt) format.
* Fix many lintian warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
  Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
3
3
 
4
4
  System call sign extender
15
15
#include <string.h>
16
16
 
17
17
#include "dwarves.h"
 
18
#include "dutil.h"
18
19
 
19
20
static const char *prefix = "sys_";
20
21
static size_t prefix_len = 4;
21
22
 
22
 
static struct tag *filter(struct tag *self, struct cu *cu,
23
 
                          void *cookie __unused)
 
23
static bool filter(struct function *f, struct cu *cu)
24
24
{
25
 
        if (self->tag == DW_TAG_subprogram) {
26
 
                struct function *f = tag__function(self);
27
 
 
28
 
                if (f->proto.nr_parms != 0) {
29
 
                        const char *name = function__name(f, cu);
30
 
 
31
 
                        if (strlen(name) > prefix_len &&
32
 
                            memcmp(name, prefix, prefix_len) == 0)
33
 
                                return self;
34
 
                }
 
25
        if (f->proto.nr_parms != 0) {
 
26
                const char *name = function__name(f, cu);
 
27
 
 
28
                if (strlen(name) > prefix_len &&
 
29
                    memcmp(name, prefix, prefix_len) == 0)
 
30
                        return false;
35
31
        }
36
 
        return NULL;
 
32
        return true;
37
33
}
38
34
 
39
35
static void zero_extend(const int regparm, const struct base_type *bt,
40
 
                        const char *parm)
 
36
                        struct cu *cu, const char *parm)
41
37
{
42
38
        const char *instr = "INVALID";
43
39
 
44
 
        switch (bt->size) {
45
 
        case 4: /* 32 bits */
 
40
        switch (bt->bit_size) {
 
41
        case 32:
46
42
                instr = "sll";
47
43
                break;
48
 
        case 2: /* 16 bits */
 
44
        case 16:
49
45
                instr = "slw";
50
46
                break;
51
 
        case 1: /* 8 bits */
 
47
        case 8:
52
48
                instr = "slb";
53
49
                break;
54
50
        }
55
51
 
 
52
        char bf[64];
56
53
        printf("\t%s\t$a%d, $a%d, 0"
57
 
               "\t/* zero extend $a%d(%s %s) from %zd to 64-bit */\n",
58
 
               instr, regparm, regparm, regparm, bt->name, parm, bt->size * 8);
 
54
               "\t/* zero extend $a%d(%s %s) from %d to 64-bit */\n",
 
55
               instr, regparm, regparm, regparm,
 
56
               base_type__name(bt, cu, bf, sizeof(bf)),
 
57
               parm, bt->bit_size);
59
58
}
60
59
 
61
 
static int emit_wrapper(struct tag *self, struct cu *cu, void *cookie __unused)
 
60
static void emit_wrapper(struct function *f, struct cu *cu)
62
61
{
63
62
        struct parameter *parm;
64
 
        struct function *f = tag__function(self);
65
63
        const char *name = function__name(f, cu);
66
64
        int regparm = 0, needs_wrapper = 0;
67
65
 
68
66
        function__for_each_parameter(f, parm) {
69
 
                const Dwarf_Off type_id = parameter__type(parm, cu);
70
 
                struct tag *type = cu__find_tag_by_id(cu, type_id);
 
67
                const uint16_t type_id = parm->tag.type;
 
68
                struct tag *type = cu__type(cu, type_id);
71
69
 
72
 
                assert(type != NULL);
 
70
                tag__assert_search_result(type);
73
71
                if (type->tag == DW_TAG_base_type) {
74
72
                        struct base_type *bt = tag__base_type(type);
 
73
                        char bf[64];
75
74
 
76
 
                        if (bt->size < 8 &&
77
 
                            strncmp(bt->name, "unsigned", 8) == 0) {
 
75
                        if (bt->bit_size < 64 &&
 
76
                            strncmp(base_type__name(bt, cu, bf, sizeof(bf)),
 
77
                                                    "unsigned", 8) == 0) {
78
78
                                if (!needs_wrapper) {
79
79
                                        printf("wrap_%s:\n", name);
80
80
                                        needs_wrapper = 1;
81
81
                                }
82
 
                                zero_extend(regparm, bt,
 
82
                                zero_extend(regparm, bt, cu,
83
83
                                            parameter__name(parm, cu));
84
84
                        }
85
85
                }
88
88
 
89
89
        if (needs_wrapper)
90
90
                printf("\tj\t%s\n\n", name);
91
 
 
92
 
 
93
 
        return 0;
94
91
}
95
92
 
96
93
static int cu__emit_wrapper(struct cu *self, void *cookie __unused)
97
94
{
98
 
        return cu__for_each_tag(self, emit_wrapper, NULL, filter);
 
95
        struct function *pos;
 
96
        uint32_t id;
 
97
 
 
98
        cu__for_each_function(self, id, pos)
 
99
                if (!filter(pos, self))
 
100
                        emit_wrapper(pos, self);
 
101
        return 0;
99
102
}
100
103
 
101
104
static void cus__emit_wrapper(struct cus *self)
103
106
        cus__for_each_cu(self, cu__emit_wrapper, NULL, NULL);
104
107
}
105
108
 
 
109
/* Name and version of program.  */
 
110
ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 
111
 
106
112
static const struct argp_option options[] = {
107
113
        {
108
114
                .key  = 'p',
119
125
{
120
126
        switch (key) {
121
127
        case ARGP_KEY_INIT:
122
 
                state->child_inputs[0] = state->input;
 
128
                if (state->child_inputs != NULL)
 
129
                        state->child_inputs[0] = state->input;
123
130
                break;
124
131
        case 'p':
125
132
                prefix = arg;
131
138
        return 0;
132
139
}
133
140
 
134
 
static const char args_doc[] = "[FILE]";
 
141
static const char args_doc[] = "FILE";
135
142
 
136
143
static struct argp argp = {
137
144
        .options  = options,
141
148
 
142
149
int main(int argc, char *argv[])
143
150
{
144
 
        int err;
145
 
        struct cus *cus = cus__new(NULL, NULL);
 
151
        int err, remaining;
 
152
        struct cus *cus = cus__new();
146
153
 
147
154
        if (cus == NULL) {
148
155
                fprintf(stderr, "%s: insufficient memory\n", argv[0]);
149
156
                return EXIT_FAILURE;
150
157
        }
151
158
 
152
 
        err = cus__loadfl(cus, &argp, argc, argv);
 
159
        if (argp_parse(&argp, argc, argv, 0, &remaining, NULL) ||
 
160
            remaining == argc) {
 
161
                argp_help(&argp, stderr, ARGP_HELP_SEE, argv[0]);
 
162
                return EXIT_FAILURE;
 
163
        }
 
164
        err = cus__load_files(cus, NULL, argv + remaining);
153
165
        if (err != 0)
154
166
                return EXIT_FAILURE;
155
167