Remove usage of unwanted binutils library
authorRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:14:53 +0000 (14:14 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:19:11 +0000 (14:19 +0200)
Change-Id: I616494d5280b87a6059149a8005911e4f7062fa3

packaging/cynara.spec
src/CMakeLists.txt
src/common/CMakeLists.txt
src/common/log/Backtrace.cpp
src/common/log/Backtrace.h

index 1d7b8c8..4b68a35 100644 (file)
@@ -22,8 +22,6 @@ BuildRequires: pkgconfig(libsystemd-journal)
 %if %{?build_type} == "DEBUG"
 
 BuildRequires: pkgconfig(libunwind)
-BuildRequires: pkgconfig(zlib)
-BuildRequires: binutils-devel
 
 %endif
 
index 6b908c3..852e0a5 100644 (file)
@@ -25,7 +25,6 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 SET(COMMON_DEPS
     ${COMMON_DEPS}
     libunwind
-    zlib
     )
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
index 5e6308a..4962b78 100644 (file)
@@ -60,9 +60,6 @@ SET_TARGET_PROPERTIES(
 IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 SET(CYNARA_DBG_LIBRARIES
     ${CYNARA_DEP_LIBRARIES}
-    -lbfd
-    -liberty
-    -ldl
     )
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
index a58c0ed..26e3e02 100644 (file)
  * @brief       Implementation of backtrace utility class.
  */
 
-#include "Backtrace.h"
-
 #include <cxxabi.h>
-#include <log/log.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <attributes/attributes.h>
+#include <log/log.h>
+
+#include "Backtrace.h"
+
 namespace Cynara {
 
 Backtrace &Backtrace::getInstance(void) {
-    static Backtrace m_instance(NULL);
+    static Backtrace m_instance;
     return m_instance;
 }
 
-Backtrace::Backtrace(bfd *abfd) :
-        m_bfd(abfd), m_found(false), m_pc(0), m_fileName(NULL),
+Backtrace::Backtrace() :
+        m_fileName(NULL),
         m_functionName(NULL), m_lineNumber(0) {
 }
 
 Backtrace::~Backtrace() {
-    if (m_bfd) {
-        bfd_close(m_bfd);
-        LOGD("Binary file closed.");
-    }
-}
-
-bool Backtrace::init(void) {
-    char exePath[BUFSIZ];
-    readlink("/proc/self/exe", exePath, BUFSIZ);
-
-    bfd_init();
-    m_bfd = bfd_openr(exePath, NULL);
-    if (m_bfd) {
-        m_bfd->flags |= BFD_DECOMPRESS;
-        if (bfd_check_format_matches(m_bfd, bfd_object, 0)) {
-            return true;
-        }
-        bfd_close(m_bfd);
-        m_bfd = NULL;
-        LOGE("Binary file check format failed.");
-    } else {
-        LOGE("Failed to open file: %s", exePath);
-    }
-
-    return false;
-}
-
-void Backtrace::findAddressInSection(bfd *abfd, asection *section, void *data) {
-    bfd_vma vma;
-    bfd_size_type size;
-
-    Backtrace *backtrace = static_cast<Backtrace*>(data);
-
-    if (backtrace->m_found) {
-        return;
-    }
-
-    if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0) {
-        return;
-    }
-
-    vma = bfd_get_section_vma(abfd, section);
-    if (backtrace->m_pc < vma) {
-        return;
-    }
-
-    size = bfd_get_section_size(section);
-    if (backtrace->m_pc >= vma + size) {
-        return;
-    }
-
-    backtrace->m_found = bfd_find_nearest_line(abfd, section, NULL,
-            backtrace->m_pc - vma, &backtrace->m_fileName,
-            &backtrace->m_functionName, &backtrace->m_lineNumber);
 }
 
-void Backtrace::getSourceInfo(unw_word_t proc_address) {
-    char addr[64];
-
-    sprintf(addr, "0x%lx", static_cast<long unsigned int>(proc_address));
-    m_pc = bfd_scan_vma(addr, NULL, 16);
-    m_found = false;
-    bfd_map_over_sections(m_bfd, findAddressInSection, this);
-
-    if (m_found) {
-        while (true) {
-            m_found = bfd_find_inliner_info(m_bfd, &m_fileName, &m_functionName,
-                    &m_lineNumber);
-            if (!m_found)
-                break;
-        }
-    } else {
-        m_fileName = "??";
-        m_functionName = "??";
-        m_lineNumber = 0;
-    }
+void Backtrace::getSourceInfo(unw_word_t proc_address UNUSED) {
+    // TODO: extract filename and line number for symbol at given address
+    m_fileName = "??";
+    m_functionName = "??";
+    m_lineNumber = 0;
 }
 
 const std::string Backtrace::buildBacktrace(void) {
@@ -132,10 +65,6 @@ const std::string Backtrace::buildBacktrace(void) {
     char *realname;
     int status;
 
-    if (m_bfd == NULL) {
-        init();
-    }
-
     unw_getcontext(&uc);
     // get rid of previous function: Backtrace::getBacktrace
     unw_init_local(&cursor, &uc);
index 568c921..b697195 100644 (file)
 #ifndef SRC_COMMON_LOG_BACKTRACE_H_
 #define SRC_COMMON_LOG_BACKTRACE_H_
 
-// Bellow two defines are needed by /usr/include/bfd.h file.
-// In fact it needs config.h generated by autotools
-// but we dont use autotools to build cynara so we don't have config.h
-// bfd.h checks for these defines
-#define PACKAGE             1
-#define PACKAGE_VERSION     1
-
-#include <bfd.h>
 #define UNW_LOCAL_ONLY
 #include <libunwind.h>
 #include <string>
@@ -52,21 +44,16 @@ public:
 private:
     static Backtrace &getInstance(void);
 
-    Backtrace(bfd *abfd);
+    Backtrace();
     Backtrace(Backtrace const &) = delete;
     ~Backtrace();
 
     void operator=(Backtrace const &) = delete;
 
-    bool init(void);
     const std::string buildBacktrace(void);
-    static void findAddressInSection(bfd *abfd, asection *section, void *data);
     void getSourceInfo(unw_word_t proc_address);
 
 private:
-    bfd *m_bfd;
-    bool m_found;
-    bfd_vma m_pc;
     const char *m_fileName;
     const char *m_functionName;
     unsigned int m_lineNumber;