Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
call-stack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
call-stack
Commits
6fe6bb79
Commit
6fe6bb79
authored
6 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
parsing
parent
c18aeead
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-3
1 addition, 3 deletions
README.md
src/main.rs
+148
-51
148 additions, 51 deletions
src/main.rs
with
149 additions
and
54 deletions
README.md
+
1
−
3
View file @
6fe6bb79
...
@@ -2,15 +2,13 @@
...
@@ -2,15 +2,13 @@
A cargo sub-commond for spanning the call stack for a
`cortex-m`
bare metal application.
A cargo sub-commond for spanning the call stack for a
`cortex-m`
bare metal application.
## Installing
## Installing
> cargo install --path <PATH_TO cargo-call-stack>
> cargo install --path <PATH_TO cargo-call-stack>
-f
## Usage
## Usage
Assume we have have an existing
`cortex-m`
bare metal application, e.g., ...
Assume we have have an existing
`cortex-m`
bare metal application, e.g., ...
> cargo call-stack --release --example hello1
> cargo call-stack --release --example hello1
## Tech notes
## Tech notes
### Cargo sub-commands
### Cargo sub-commands
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
148
−
51
View file @
6fe6bb79
...
@@ -4,6 +4,80 @@ use std::io::{self, Read, Write};
...
@@ -4,6 +4,80 @@ use std::io::{self, Read, Write};
use
std
::
process
::{
Command
,
Stdio
};
use
std
::
process
::{
Command
,
Stdio
};
use
std
::{
env
,
str
};
use
std
::{
env
,
str
};
#[derive(Debug)]
struct
Out
{
hash
:
Option
<
String
>
,
crate_name
:
Option
<
String
>
,
out_dir
:
Option
<
String
>
,
}
// Parse the output from rustc
// we skip the last line (Finished ...)
// and look for `--crate-name x`, `extra-filename=y` and `--out dir z`
//
// Notice, the parsing is a bit of a hack, implemnting look ahead using flags.
fn
parse_out
(
out_str
:
&
str
)
->
Out
{
let
mut
out
=
Out
{
hash
:
None
,
crate_name
:
None
,
out_dir
:
None
,
};
let
output
=
out_str
;
let
mut
i
=
output
.lines
()
.into_iter
();
i
.next_back
();
// skip last line (Finished)
if
let
Some
(
line
)
=
i
.next_back
()
{
let
mut
crate_name
=
false
;
let
mut
out_dir
=
false
;
for
part
in
line
.split
(
' '
)
{
if
crate_name
{
out
.crate_name
=
Some
(
part
.to_string
());
crate_name
=
false
;
}
else
if
out_dir
{
out
.out_dir
=
Some
(
part
.to_string
());
out_dir
=
false
;
}
else
if
part
.starts_with
(
"--crate-name"
)
{
crate_name
=
true
;
}
else
if
part
.starts_with
(
"--out-dir"
)
{
out_dir
=
true
;
}
else
if
part
.starts_with
(
"extra-filename="
)
{
out
.hash
=
Some
(
part
.split
(
'='
)
.nth
(
1
)
.unwrap
()
.to_string
());
}
}
}
out
}
fn
parse_output
(
output
:
&
str
)
->
(
Option
<&
str
>
,
Option
<&
str
>
,
Option
<&
str
>
)
{
let
mut
suffix
=
None
;
let
mut
crate_name
=
None
;
let
mut
example
=
None
;
let
output
=
str
::
from_utf8
(
output
.as_bytes
())
.unwrap
();
println!
(
"here ..."
);
let
mut
i
=
output
.lines
()
.into_iter
();
i
.next_back
();
// skip last line
if
let
Some
(
line
)
=
i
.next_back
()
{
let
mut
b
=
false
;
for
part
in
line
.split
(
' '
)
{
if
b
{
crate_name
=
Some
(
part
);
b
=
false
;
}
else
if
part
.starts_with
(
"--crate-name"
)
{
b
=
true
;
println!
(
"----- here ---------- {:?}"
,
crate_name
);
}
else
if
part
.starts_with
(
"extra-filename="
)
{
suffix
=
part
.split
(
'='
)
.nth
(
1
);
println!
(
"----- there ----------"
);
}
else
if
part
.starts_with
(
"example"
)
{
example
=
part
.split
(
'/'
)
.nth
(
1
);
println!
(
"----- there ----------"
);
};
}
//}
}
(
suffix
,
crate_name
,
example
)
}
fn
main
()
{
fn
main
()
{
println!
(
"start sub command"
);
println!
(
"start sub command"
);
// first argument is the path to this binary; the second argument is always "call-stack" -- both can
// first argument is the path to this binary; the second argument is always "call-stack" -- both can
...
@@ -57,60 +131,74 @@ fn main() {
...
@@ -57,60 +131,74 @@ fn main() {
}
}
}
}
// find out the argument passed to `--example`, if used at all
let
out
=
parse_out
(
str
::
from_utf8
(
&
output
)
.unwrap
());
let
mut
example
=
None
;
println!
(
"{:?}"
,
out
);
let
mut
iargs
=
args
.iter
();
// } else {
while
let
Some
(
arg
)
=
iargs
.next
()
{
// panic!("could not determine hash, please recompile in `--release` mode");
if
arg
==
"--example"
{
// }
example
=
iargs
.next
();
break
;
}
}
// get the suffix of the example
let
(
example
,
suffix
)
=
if
let
Some
(
example
)
=
example
{
let
mut
suffix
=
None
;
let
output
=
str
::
from_utf8
(
&
output
)
.unwrap
();
println!
(
"here ..."
);
for
line
in
output
.lines
()
{
if
line
.contains
(
&
format!
(
"examples/{}.rs"
,
example
))
{
for
part
in
line
.split
(
' '
)
{
if
part
.starts_with
(
"extra-filename="
)
{
suffix
=
part
.split
(
'='
)
.nth
(
1
);
}
}
}
}
match
suffix
{
None
=>
panic!
(
format!
(
"Cannot determine hash, please run `touch example/{}.rs` to force recompiltaion."
,
example
)),
Some
(
s
)
=>
(
example
,
s
),
}
}
else
{
// nothing to do if the user didn't use `--example`
println!
(
"try to determinte hash"
);
let
output
=
str
::
from_utf8
(
&
output
)
.unwrap
();
println!
(
"here ..."
);
let
mut
suffix
=
None
;
for
line
in
output
.lines
()
{
for
part
in
line
.split
(
' '
)
{
if
part
.starts_with
(
"extra-filename="
)
{
suffix
=
part
.split
(
'='
)
.nth
(
1
);
}
}
}
match
suffix
{
None
=>
panic!
(
format!
(
"Cannot determine hash, please force recompiltaion."
)),
Some
(
s
)
=>
panic!
(
"main hash {}"
,
s
),
}
// return;
};
println!
(
"{:?}"
,
(
example
,
suffix
));
// find out the argument passed to `--example`, if used at all
// let mut example = None;
// let mut iargs = args.iter();
// while let Some(arg) = iargs.next() {
// if arg == "--example" {
// example = iargs.next();
// break;
// }
// }
// let output = str::from_utf8(&output).unwrap();
// if let (Some(hash), Some(crate_name), example) = parse_output(&output) {
// println!("{:?}, {:?}, {:?}", example, hash, crate_name);
// } else {
// panic!("could not determine hash, please recompile in `--release` mode");
// }
// // get the suffix of the example
// let (example, suffix) = if let Some(example) = example {
// let mut suffix = None;
// let output = str::from_utf8(&output).unwrap();
// println!("here ...");
// for line in output.lines() {
// if line.contains(&format!("examples/{}.rs", example)) {
// for part in line.split(' ') {
// if part.starts_with("extra-filename=") {
// suffix = part.split('=').nth(1);
// }
// }
// }
// }
// match suffix {
// None => panic!(format!(
// "Cannot determine hash, please run `touch example/{}.rs` to force recompiltaion.",
// example
// )),
// Some(s) => (example, s),
// }
// } else {
// // nothing to do if the user didn't use `--example`
// println!("try to determinte hash");
// let output = str::from_utf8(&output).unwrap();
// println!("here ...");
// let mut suffix = None;
// for line in output.lines() {
// for part in line.split(' ') {
// if part.starts_with("extra-filename=") {
// suffix = part.split('=').nth(1);
// }
// }
// }
// match suffix {
// None => panic!(format!(
// "Cannot determine hash, please force recompiltaion."
// )),
// Some(s) => panic!("main hash {}", s),
// }
// // return;
// };
// println!("{:?}", (example, suffix));
/*
/*
let profile = if args.iter().any(|a| a == "--release") {
let profile = if args.iter().any(|a| a == "--release") {
...
@@ -152,3 +240,12 @@ fn main() {
...
@@ -152,3 +240,12 @@ fn main() {
unsafe { libc::getuid() }
unsafe { libc::getuid() }
*/
*/
}
}
// blx511
// ARN
// LINDGREN
// PER
// 03021968 Piteå
// Swedish
// pass#
// Aquamarine
// Tourist
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment