$(shell) function in GNU makefile results in 'unterminated call to function shell: missing )' - grep

Description:
I have the following snippet within my GNU makefile:
test:=$(shell grep '#pragma' test_types.h)
$(info test:$(test))
The above results in the following error message:
*** unterminated call to function 'shell': missing ')'. STOP
However if I remove the '#' from the snippet above:
test:=$(shell grep 'pragma' test_types.h)
$(info test:$(test))
The output is:
test: #pragma pack(push, 1) #pragma pack(pop)
If I run the following directly from the command line: grep '#pragma' test_types.h. The output is again:
#pragma pack(push, 1) #pragma pack(pop)
Question:
What is causing the shell function behaviour when combining grep with a search for # within a GNU makefile?

It is interpreting the # as the start of a comment, so the rest of the line is no longer seen.
Escape the character as \# instead and it will work.

Related

How can I print 10 lines above and until a matching word below for each matching line?

I need to parse log file so I output the errors(with the stack trace below), and 10 lines above each error.
For example:
2017-10-29 00:00:10,440 INFO ...
2017-10-29 00:00:10,473 WARN ...
2017-10-29 00:00:10,504 INFO ...
2017-10-29 00:00:10,547 INFO ...
2017-10-29 00:00:10,610 INFO ...
2017-10-29 00:00:11,176 WARN ...
2017-10-29 00:00:11,894 WARN ..
2017-10-29 00:00:11,900 INFO ...
2017-10-29 00:00:11,900 INFO ...
2017-10-29 00:00:12,632 WARN ...
2017-10-29 00:00:12,946 ERROR...
...(stack trace)...
...(stack trace)...
...(stack trace)...
2017-10-29 00:00:12,946 WARN
I need to output 10 lines above the ERROR until the the date(2017-10-29) below(not including the line of the date)
Thought about doing it with grep -n -B10 "ERROR"(for the 10 lines above) and sed '/ERROR/,/29/p'(for the stack trace) but how do I combine the two?
With grep + head pipeline:
grep -B10 'ERROR' g1 | head -n -1
This might work for you (GNU sed):
sed -n ':a;N;/ERROR/bb;s/[^\n]\+/&/11;Ta;D;:b;p;n;/2017-10-29$/!bb' file
Gather up at most 10 lines in the pattern space then use these lines as moving window through the file. When the string ERROR is encountered print the window and then any further lines until (but not including) the string 2017-10-29 is matched. Repeat if necessary.
Try this one
grep -no -B10 ' [0-9:,]* ERROR.*' infile
Need perhaps to substitute ' ' by [[:blank:]]
here is a way using awk:
awk ' {a[++b]=$0}
/^([0-9]{2,4}-?){3}/ {f=0}
/ERROR/ {f=1; for(i=NR-10;i<NR;i++) print a[i]}
f' file
we store each line to array. When matching a date log line, we unset the flag. When matching ERROR we set the flag and we print last 10 lines of the array. And when flag is on, we print (default action so we wrote just f)
This should print expected lines for all existing ERRORs in file.
note: the date regexp used is not strict but seems enough for the case.

addr2line - inline function code line missing

I have a android arm64 trace:
#02 pc 00000000000c61c0 /system/lib64/libmedia.so (_ZN7android10AudioTrack16AudioTrackThread10threadLoopEv+84)
I use below command to parser the code line information:
aarch64-linux-addr2line -f -C -e symbols/system/lib64/libmedia.so 00000000000c61cc
android::Condition::wait(android::Mutex&)
/proc/self/cwd/system/core/include/utils/Condition.h:106
Obviously, wait() is a inline function so addr2line didn't find the code line in threadLoop but use the wait() code line instead.
How to get the right line number in threadLoop? I am using binutils-2.28 to build addr2line tool.
Have you tried the -i option?
-i --inlines Unwind inlined functions

How do I get clang to dump the AST without color?

Using clang-check to dump a source code's AST, can be done with the following command:
$ clang-check -ast-dump file.c --
However, the output of this command will appear colorful within the terminal.
When I direct the output to a file, I'm stuck with all of the color escape codes:
$ clang-check -ast-dump file.c -- > out.txt
example:
[0;1;32mTranslationUnitDecl[0m[0;33m 0x227c5c0[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227cac0[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __int128_t[0m [0;32m'__int128'[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227cb20[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __uint128_t[0m [0;32m'unsigned __int128'[0m
[0;34m|-[0m[0;1;32mTypedefDecl[0m[0;33m 0x227ce70[0m <[0;33m<invalid sloc>[0m> [0;33m<invalid sloc>[0m implicit[0;1;36m __builtin_va_list[0m [0;32m'__va_list_tag [1]'[0m
...
Is there a flag to disable colors in clang-check?
I tried adding the following flag, but it did not work:
--extra-arg="--no-color-diagnostics"
You are almost correct. Try
$ clang-check -ast-dump test.c --extra-arg="-fno-color-diagnostics" --
Additionally, -fno-diagnostics-color and -fdiagnostics-color=never also seems to work
Reference: http://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics

Filter Doxygen output with grep

I want to filter the doxygen warnings with grep, to supress the undocumented parameter warning for certain parameters. I am trying this:
doxygen doxycfgfile | grep -v "parameter x"
however this seems to have absolutely no effect on the output. Neither the lines containing parameter x are suppressed nor all other lines. The output appears to be exactly the same.
I am using tcsh.
Presumably this is because the undocumented parameter warning messages are being written to standard error (stderr), rather than standard out (stdout). With the pipe (|) you are only piping stdout to grep's input.
You could try doing something like
doxygen doxycfgfile |& grep -v "parameter x"
From the advanced bash scripting guide:
If |& is used, the standard error of command1 is connected to command2's standard input through the pipe; it is shorthand for 2>&1 |.
Note, this was added in Bash 4, so for earlier versions you will have you use 2>&1 | in place of |&.
Alternatively, you could just get rid of the standard error output, using something like
doxygen doxycfgfile 2>/dev/null
This answer on askubuntu was the source for my answer.

javac flag to print only the error locations

Is it possible to make javac output only the error locations and the error messages, and hide the source code dump?
Now I get:
$ javac t.java
t.java:1: <identifier> expected
class {
^
t.java:2: reached end of file while parsing
bar
^
t.java:4: reached end of file while parsing
^
3 errors
I want to get only:
$ javac ... t.java
t.java:1: <identifier> expected
t.java:2: reached end of file while parsing
t.java:4: reached end of file while parsing
I think there is no flag you could pass to javac, but you can simply filter the output through any program which removes the superfluous lines. Here an example with grep:
javac t.java 2>&1 | egrep '^[a-zA-Z0-9_/]+\.java:[0-9]+: '
You might have to change the part matching the file name if you have strange letters in your file name - this seems to work for the ASCII subset.

Resources