Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging with symbols #24

Merged
merged 8 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
language: rust

addons:
apt:
packages:
- qemu-system-arm

matrix:
include:
- rust: beta

matrix:
include:
- rust: nightly

install:
- bash ci/install.sh
- export PATH="$PATH:$PWD/gcc/bin"
- export PATH="$PATH:$PWD/gcc/bin:$PWD/qemu"

script:
- bash ci/script.sh
Expand Down
4 changes: 4 additions & 0 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ main() {

curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj

mkdir qemu
curl -L https://github.com/japaric/qemu-bin/raw/master/14.04/qemu-system-arm-2.12.0 > qemu/qemu-system-arm
chmod +x qemu/qemu-system-arm

rustup component add llvm-tools-preview

curl -LSfs https://japaric.github.io/trust/install.sh | \
Expand Down
6 changes: 6 additions & 0 deletions ci/logging/app/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[target.thumbv7m-none-eabi]
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
rustflags = ["-C", "link-arg=-Tlink.x"]

[build]
target = "thumbv7m-none-eabi"
13 changes: 13 additions & 0 deletions ci/logging/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"

[dependencies]
cortex-m-semihosting = "0.3.1"
rt = { path = "../rt" }

[profile.release]
codegen-units = 1
lto = true
2 changes: 2 additions & 0 deletions ci/logging/app/dev.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
00001fe1 l .rodata 00000001 Goodbye
00001fe0 l .rodata 00000001 Hello, world!
2 changes: 2 additions & 0 deletions ci/logging/app/dev.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0x1fe0
0x1fe1
2 changes: 2 additions & 0 deletions ci/logging/app/release.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
00000a7d l .rodata 00000001 Goodbye
00000a7c l .rodata 00000001 Hello, world!
2 changes: 2 additions & 0 deletions ci/logging/app/release.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0xa7c
0xa7d
27 changes: 27 additions & 0 deletions ci/logging/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_main]
#![no_std]

use core::fmt::Write;
use cortex_m_semihosting::{debug, hio};

use rt::entry;

entry!(main);

fn main() -> ! {
let mut hstdout = hio::hstdout().unwrap();

#[export_name = "Hello, world!"]
static A: u8 = 0;

writeln!(hstdout, "{:#x}", &A as *const u8 as usize);

#[export_name = "Goodbye"]
static B: u8 = 0;

writeln!(hstdout, "{:#x}", &B as *const u8 as usize);

debug::exit(debug::EXIT_SUCCESS);

loop {}
}
9 changes: 9 additions & 0 deletions ci/logging/app2/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[target.thumbv7m-none-eabi]
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tlog.x", # <- NEW!
]

[build]
target = "thumbv7m-none-eabi"
13 changes: 13 additions & 0 deletions ci/logging/app2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"

[dependencies]
cortex-m-semihosting = "0.3.1"
rt = { path = "../rt" }

[profile.release]
codegen-units = 1
lto = true
2 changes: 2 additions & 0 deletions ci/logging/app2/dev.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
00000001 l .log 00000001 Goodbye
00000000 l .log 00000001 Hello, world!
1 change: 1 addition & 0 deletions ci/logging/app2/dev.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001
6 changes: 6 additions & 0 deletions ci/logging/app2/log.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SECTIONS
{
.log 0 (INFO) : {
*(.log);
}
}
30 changes: 30 additions & 0 deletions ci/logging/app2/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![no_main]
#![no_std]

use cortex_m_semihosting::{debug, hio};

use rt::entry;

entry!(main);

fn main() -> ! {
let mut hstdout = hio::hstdout().unwrap();

#[export_name = "Hello, world!"]
#[link_section = ".log"] // <- NEW!
static A: u8 = 0;

let address = &A as *const u8 as usize as u8;
hstdout.write_all(&[address]).unwrap(); // <- CHANGED!

#[export_name = "Goodbye"]
#[link_section = ".log"] // <- NEW!
static B: u8 = 0;

let address = &B as *const u8 as usize as u8;
hstdout.write_all(&[address]).unwrap(); // <- CHANGED!

debug::exit(debug::EXIT_SUCCESS);

loop {}
}
1 change: 1 addition & 0 deletions ci/logging/app3/.cargo
10 changes: 10 additions & 0 deletions ci/logging/app3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"

[dependencies]
cortex-m-semihosting = "0.3.1"
log = { path = "../log" }
rt = { path = "../rt" }
2 changes: 2 additions & 0 deletions ci/logging/app3/dev.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
00000001 l .log 00000001 Goodbye
00000000 l .log 00000001 Hello, world!
1 change: 1 addition & 0 deletions ci/logging/app3/dev.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001
37 changes: 37 additions & 0 deletions ci/logging/app3/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![no_main]
#![no_std]

use cortex_m_semihosting::{
debug,
hio::{self, HStdout},
};

use log::{log, Log};
use rt::entry;

struct Logger {
hstdout: HStdout,
}

impl Log for Logger {
type Error = ();

fn log(&mut self, address: u8) -> Result<(), ()> {
self.hstdout.write_all(&[address])
}
}

entry!(main);

fn main() -> ! {
let hstdout = hio::hstdout().unwrap();
let mut logger = Logger { hstdout };

log!(logger, "Hello, world!");

log!(logger, "Goodbye");

debug::exit(debug::EXIT_SUCCESS);

loop {}
}
1 change: 1 addition & 0 deletions ci/logging/app4/.cargo
10 changes: 10 additions & 0 deletions ci/logging/app4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "app"
version = "0.1.0"

[dependencies]
cortex-m-semihosting = "0.3.1"
log = { path = "../log2" }
rt = { path = "../rt" }
3 changes: 3 additions & 0 deletions ci/logging/app4/dev.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
00000000 l .log 00000001 Goodbye
00000001 l .log 00000001 Hello, world!
00000001 .log 00000000 __log_warning_start__
1 change: 1 addition & 0 deletions ci/logging/app4/dev.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0100
37 changes: 37 additions & 0 deletions ci/logging/app4/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![no_main]
#![no_std]

use cortex_m_semihosting::{
debug,
hio::{self, HStdout},
};

use log::{error, warn, Log};
use rt::entry;

entry!(main);

fn main() -> ! {
let hstdout = hio::hstdout().unwrap();
let mut logger = Logger { hstdout };

warn!(logger, "Hello, world!"); // <- CHANGED!

error!(logger, "Goodbye"); // <- CHANGED!

debug::exit(debug::EXIT_SUCCESS);

loop {}
}

struct Logger {
hstdout: HStdout,
}

impl Log for Logger {
type Error = ();

fn log(&mut self, address: u8) -> Result<(), ()> {
self.hstdout.write_all(&[address])
}
}
7 changes: 7 additions & 0 deletions ci/logging/log/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "log"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"

[dependencies]
12 changes: 12 additions & 0 deletions ci/logging/log/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::{env, error::Error, fs::File, io::Write, path::PathBuf};

fn main() -> Result<(), Box<Error>> {
// Put the linker script somewhere the linker can find it
let out = PathBuf::from(env::var("OUT_DIR")?);

File::create(out.join("log.x"))?.write_all(include_bytes!("log.x"))?;

println!("cargo:rustc-link-search={}", out.display());

Ok(())
}
6 changes: 6 additions & 0 deletions ci/logging/log/log.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SECTIONS
{
.log 0 (INFO) : {
*(.log);
}
}
18 changes: 18 additions & 0 deletions ci/logging/log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![no_std]

pub trait Log {
type Error;

fn log(&mut self, address: u8) -> Result<(), Self::Error>;
}

#[macro_export]
macro_rules! log {
($logger:expr, $string:expr) => {{
#[export_name = $string]
#[link_section = ".log"]
static SYMBOL: u8 = 0;

$crate::Log::log(&mut $logger, &SYMBOL as *const u8 as usize as u8)
}};
}
7 changes: 7 additions & 0 deletions ci/logging/log2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "log"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"

[dependencies]
1 change: 1 addition & 0 deletions ci/logging/log2/build.rs
8 changes: 8 additions & 0 deletions ci/logging/log2/log.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SECTIONS
{
.log 0 (INFO) : {
*(.log.error);
__log_warning_start__ = .;
*(.log.warning);
}
}
31 changes: 31 additions & 0 deletions ci/logging/log2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![no_std]

pub trait Log {
type Error;

fn log(&mut self, address: u8) -> Result<(), Self::Error>;
}

/// Logs messages at the ERROR log level
#[macro_export]
macro_rules! error {
($logger:expr, $string:expr) => {{
#[export_name = $string]
#[link_section = ".log.error"] // <- CHANGED!
static SYMBOL: u8 = 0;

$crate::Log::log(&mut $logger, &SYMBOL as *const u8 as usize as u8)
}};
}

/// Logs messages at the WARNING log level
#[macro_export]
macro_rules! warn {
($logger:expr, $string:expr) => {{
#[export_name = $string]
#[link_section = ".log.warning"] // <- CHANGED!
static SYMBOL: u8 = 0;

$crate::Log::log(&mut $logger, &SYMBOL as *const u8 as usize as u8)
}};
}
1 change: 1 addition & 0 deletions ci/logging/rt
Loading