1
/*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
3
|* The LLVM Compiler Infrastructure *|
5
|* This file is distributed under the University of Illinois Open Source *|
6
|* License. See LICENSE.TXT for details. *|
8
|*===----------------------------------------------------------------------===*|
10
|* This file implements the --object-list-sections and --object-list-symbols *|
11
|* commands in llvm-c-test. *|
13
\*===----------------------------------------------------------------------===*/
15
#include "llvm-c-test.h"
16
#include "llvm-c/Object.h"
20
int object_list_sections(void) {
21
LLVMMemoryBufferRef MB;
23
LLVMSectionIteratorRef sect;
26
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
27
fprintf(stderr, "Error reading file: %s\n", msg);
31
O = LLVMCreateObjectFile(MB);
33
fprintf(stderr, "Error reading object\n");
37
sect = LLVMGetSections(O);
38
while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
39
printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
40
LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
42
LLVMMoveToNextSection(sect);
45
LLVMDisposeSectionIterator(sect);
47
LLVMDisposeObjectFile(O);
52
int object_list_symbols(void) {
53
LLVMMemoryBufferRef MB;
55
LLVMSectionIteratorRef sect;
56
LLVMSymbolIteratorRef sym;
59
if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
60
fprintf(stderr, "Error reading file: %s\n", msg);
64
O = LLVMCreateObjectFile(MB);
66
fprintf(stderr, "Error reading object\n");
70
sect = LLVMGetSections(O);
71
sym = LLVMGetSymbols(O);
72
while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
74
LLVMMoveToContainingSection(sect, sym);
75
printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
76
LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
77
LLVMGetSectionName(sect));
79
LLVMMoveToNextSymbol(sym);
82
LLVMDisposeSymbolIterator(sym);
84
LLVMDisposeObjectFile(O);