Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45e8f67d authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Convert remaining logs to fmtlib

Forbid the use of LOG_* macros in favor
of DEBUG, INFO, WARNING, ERROR, FATAL.
LOG_* are kept in os/log.h for the packet runtime.

Bug: 284355200
Test: m root-canal
Change-Id: I906ec7bda9547065f2976dbb70532250a434378f
parent 5a8a36c4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@ bool crash_callback(const void* crash_context, size_t crash_context_size,
  }
  }
  ERROR("Backtrace:");
  ERROR("Backtrace:");
  for (const auto& frame : data.frames) {
  for (const auto& frame : data.frames) {
    ERROR("{}", unwinder.FormatFrame(frame).c_str());
    ERROR("{}", unwinder.FormatFrame(frame));
  }
  }
  return true;
  return true;
}
}
+0 −14
Original line number Original line Diff line number Diff line
@@ -69,20 +69,6 @@ static void Log(Verbosity verb, char const* file, int line, char const* format,
  rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \
  rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \
                      __VA_ARGS__)
                      __VA_ARGS__)


// TODO: still required by the generated HCI parser and serializer backend.
#define LOG_INFO(...)                                                       \
  rootcanal::log::Log(rootcanal::log::Verbosity::kInfo, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_WARN(...)                                                          \
  rootcanal::log::Log(rootcanal::log::Verbosity::kWarning, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_ERROR(...)                                                       \
  rootcanal::log::Log(rootcanal::log::Verbosity::kError, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_ALWAYS_FATAL(...)                                                \
  rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))

#define ASSERT(x)                                                       \
#define ASSERT(x)                                                       \
  __builtin_expect((x) != 0, true) ||                                   \
  __builtin_expect((x) != 0, true) ||                                   \
      (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, \
      (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, \
+13 −0
Original line number Original line Diff line number Diff line
@@ -18,3 +18,16 @@
// FIXME: Change hci_packets.h to not depend on os/log.h
// FIXME: Change hci_packets.h to not depend on os/log.h
//        and remove this.
//        and remove this.
#include "include/log.h"
#include "include/log.h"

#define LOG_INFO(...)                                                       \
  rootcanal::log::Log(rootcanal::log::Verbosity::kInfo, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_WARN(...)                                                          \
  rootcanal::log::Log(rootcanal::log::Verbosity::kWarning, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_ERROR(...)                                                       \
  rootcanal::log::Log(rootcanal::log::Verbosity::kError, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
#define LOG_ALWAYS_FATAL(...)                                                \
  rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \
                      "{}", fmt::sprintf(__VA_ARGS__))
+4 −5
Original line number Original line Diff line number Diff line
@@ -96,18 +96,17 @@ bool AclConnectionHandler::CreatePendingLeConnection(
    auto connection = std::get<AclConnection>(pair);
    auto connection = std::get<AclConnection>(pair);
    if (connection.GetAddress() == peer ||
    if (connection.GetAddress() == peer ||
        connection.GetResolvedAddress() == resolved_peer) {
        connection.GetResolvedAddress() == resolved_peer) {
      LOG_INFO("%s: %s is already connected", __func__,
      INFO("{}: {} is already connected", __func__, peer);
               peer.ToString().c_str());
      if (connection.GetResolvedAddress() == resolved_peer) {
      if (connection.GetResolvedAddress() == resolved_peer) {
        LOG_INFO("%s: allowing a second connection with %s", __func__,
        INFO("{}: allowing a second connection with {}", __func__,
                 resolved_peer.ToString().c_str());
             resolved_peer);
      } else {
      } else {
        return false;
        return false;
      }
      }
    }
    }
  }
  }
  if (le_connection_pending_) {
  if (le_connection_pending_) {
    LOG_INFO("%s: connection already pending", __func__);
    INFO("{}: connection already pending", __func__);
    return false;
    return false;
  }
  }
  le_connection_pending_ = true;
  le_connection_pending_ = true;
+20 −19
Original line number Original line Diff line number Diff line
@@ -2055,9 +2055,9 @@ LinkLayerController::LinkLayerController(const Address& address,
                std::vector(data, data + len));
                std::vector(data, data + len));


            if (!controller->connections_.HasHandle(acl_connection_handle)) {
            if (!controller->connections_.HasHandle(acl_connection_handle)) {
              LOG_ERROR(
              ERROR(
                  "Dropping LLCP packet sent for unknown connection handle "
                  "Dropping LLCP packet sent for unknown connection handle "
                  "0x%x",
                  "0x{:x}",
                  acl_connection_handle);
                  acl_connection_handle);
              return;
              return;
            }
            }
@@ -4037,7 +4037,7 @@ void LinkLayerController::IncomingLlcpPacket(
  uint16_t acl_connection_handle = connections_.GetHandleOnlyAddress(address);
  uint16_t acl_connection_handle = connections_.GetHandleOnlyAddress(address);


  if (acl_connection_handle == kReservedHandle) {
  if (acl_connection_handle == kReservedHandle) {
    LOG_INFO("Dropping LLCP packet since connection does not exist");
    INFO(id_, "Dropping LLCP packet since connection does not exist");
    return;
    return;
  }
  }


@@ -4058,8 +4058,8 @@ void LinkLayerController::IncomingLeConnectedIsochronousPdu(


  if (!link_layer_get_cis_connection_handle(ll_.get(), cig_id, cis_id,
  if (!link_layer_get_cis_connection_handle(ll_.get(), cig_id, cis_id,
                                            &cis_connection_handle)) {
                                            &cis_connection_handle)) {
    LOG_INFO(
    INFO(id_,
        "Dropping CIS pdu received on disconnected CIS cig_id=%d, cis_id=%d",
         "Dropping CIS pdu received on disconnected CIS cig_id={}, cis_id={}",
         cig_id, cis_id);
         cig_id, cis_id);
    return;
    return;
  }
  }
@@ -4104,9 +4104,9 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) {
  // Controller (which is returned using the ISO_Data_Packet_Length return
  // Controller (which is returned using the ISO_Data_Packet_Length return
  // parameter of the LE Read Buffer Size command).
  // parameter of the LE Read Buffer Size command).
  if (iso_data_load.size() > properties_.iso_data_packet_length) {
  if (iso_data_load.size() > properties_.iso_data_packet_length) {
    LOG_ALWAYS_FATAL(
    FATAL(id_,
        "Received ISO HCI packet with ISO_Data_Load_Length (%zu) larger than"
          "Received ISO HCI packet with ISO_Data_Load_Length ({}) larger than"
        " the controller buffer size ISO_Data_Packet_Length (%d)",
          " the controller buffer size ISO_Data_Packet_Length ({})",
          iso_data_load.size(), properties_.iso_data_packet_length);
          iso_data_load.size(), properties_.iso_data_packet_length);
  }
  }


@@ -4115,7 +4115,7 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) {
      (pb_flag ==
      (pb_flag ==
           bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT ||
           bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT ||
       pb_flag == bluetooth::hci::IsoPacketBoundaryFlag::LAST_FRAGMENT)) {
       pb_flag == bluetooth::hci::IsoPacketBoundaryFlag::LAST_FRAGMENT)) {
    LOG_ALWAYS_FATAL(
    FATAL(id_,
          "Received ISO HCI packet with TS_Flag set, but no ISO Header is "
          "Received ISO HCI packet with TS_Flag set, but no ISO Header is "
          "expected");
          "expected");
  }
  }
@@ -4129,7 +4129,7 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) {
  if (!link_layer_get_cis_information(ll_.get(), cis_connection_handle,
  if (!link_layer_get_cis_information(ll_.get(), cis_connection_handle,
                                      &acl_connection_handle, &cig_id, &cis_id,
                                      &acl_connection_handle, &cig_id, &cis_id,
                                      &max_sdu_length)) {
                                      &max_sdu_length)) {
    LOG_INFO("Ignoring CIS pdu received on disconnected CIS handle=%d",
    INFO(id_, "Ignoring CIS pdu received on disconnected CIS handle={}",
         cis_connection_handle);
         cis_connection_handle);
    return;
    return;
  }
  }
@@ -4166,9 +4166,10 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) {
    // Validate that the Host stack is not sending ISO SDUs that are larger
    // Validate that the Host stack is not sending ISO SDUs that are larger
    // that what was configured for the CIS.
    // that what was configured for the CIS.
    if (iso_sdu_.size() > max_sdu_length) {
    if (iso_sdu_.size() > max_sdu_length) {
      LOG_WARN(
      WARNING(
          "attempted to send an SDU of length %zu that exceeds the configure "
          id_,
          "Max_SDU_Length (%u)",
          "attempted to send an SDU of length {} that exceeds the configure "
          "Max_SDU_Length ({})",
          iso_sdu_.size(), max_sdu_length);
          iso_sdu_.size(), max_sdu_length);
      return;
      return;
    }
    }
@@ -5226,7 +5227,7 @@ void LinkLayerController::MakePeripheralConnection(const Address& addr,


  uint16_t handle = connections_.CreateConnection(addr, GetAddress());
  uint16_t handle = connections_.CreateConnection(addr, GetAddress());
  if (handle == kReservedHandle) {
  if (handle == kReservedHandle) {
    LOG_INFO("CreateConnection failed");
    INFO(id_, "CreateConnection failed");
    return;
    return;
  }
  }
  ASSERT(link_manager_add_link(
  ASSERT(link_manager_add_link(
Loading