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;
25 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
26 fprintf(stderr, "Error reading file: %s\n", msg);
30 O = LLVMCreateObjectFile(MB);
32 fprintf(stderr, "Error reading object\n");
36 LLVMSectionIteratorRef sect = LLVMGetSections(O);
37 while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
38 printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
39 LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
41 LLVMMoveToNextSection(sect);
44 LLVMDisposeSectionIterator(sect);
46 LLVMDisposeObjectFile(O);
51 int object_list_symbols(void) {
52 LLVMMemoryBufferRef MB;
56 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
57 fprintf(stderr, "Error reading file: %s\n", msg);
61 O = LLVMCreateObjectFile(MB);
63 fprintf(stderr, "Error reading object\n");
67 LLVMSectionIteratorRef sect = LLVMGetSections(O);
68 LLVMSymbolIteratorRef sym = LLVMGetSymbols(O);
69 while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
71 LLVMMoveToContainingSection(sect, sym);
72 printf("%s @0x%08" PRIx64 "/0x%08" PRIx64 " +%" PRIu64 " (%s)\n",
73 LLVMGetSymbolName(sym), LLVMGetSymbolAddress(sym),
74 LLVMGetSymbolFileOffset(sym), LLVMGetSymbolSize(sym),
75 LLVMGetSectionName(sect));
77 LLVMMoveToNextSymbol(sym);
80 LLVMDisposeSymbolIterator(sym);
82 LLVMDisposeObjectFile(O);