blob: 5b0bb299ec070bf9416547378af7e4b138d32642 [file] [log] [blame]
Ulrich Drepper515d8d72008-01-03 07:41:03 +00001/* Copyright (C) 2005, 2008 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02002 This file is part of elfutils.
Ulrich Drepper515d8d72008-01-03 07:41:03 +00003 Written by Ulrich Drepper <drepper@redhat.com>, 2007.
Ulrich Drepper3cbdd382008-01-02 17:44:39 +00004
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
Ulrich Drepper3cbdd382008-01-02 17:44:39 +00007
Mark Wielaardde2ed972012-06-05 17:15:16 +02008 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
11
12 or
13
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
17
18 or both in parallel, as here.
19
20 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper515d8d72008-01-03 07:41:03 +000021 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
Mark Wielaardde2ed972012-06-05 17:15:16 +020025 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepper3cbdd382008-01-02 17:44:39 +000028
29#ifdef HAVE_CONFIG_H
30# include <config.h>
31#endif
32
33#include <string.h>
34
35#include "libasmP.h"
36
37
38struct buffer
39{
40 char *buf;
41 size_t len;
42};
43
44
45static int
46buffer_cb (char *str, size_t len, void *arg)
47{
48 struct buffer *buffer = (struct buffer *) arg;
49
50 if (len > buffer->len)
51 /* Return additional needed space. */
52 return len - buffer->len;
53
54 buffer->buf = mempcpy (buffer->buf, str, len);
55 buffer->len = len;
56
57 return 0;
58}
59
60
61int
62disasm_str (DisasmCtx_t *ctx, const uint8_t **startp, const uint8_t *end,
63 GElf_Addr addr, const char *fmt, char **bufp, size_t len,
64 void *symcbarg)
65{
66 struct buffer buffer = { .buf = *bufp, .len = len };
67
68 int res = INTUSE(disasm_cb) (ctx, startp, end, addr, fmt, buffer_cb, &buffer,
69 symcbarg);
70 *bufp = buffer.buf;
71 return res;
72}