How do I break on all functions that matches a pattern? - gdb

I'm trying to break on all pthread functions, but it looks like gdb doesn't support wildcard here:
(gdb) b pthread_*
Function "pthread_*" not defined.
Any ideas?

Use rbreak ^pthread_
From GDB: Setting Breakpoints:
rbreak regex
Set breakpoints on all functions matching the regular expression regex.
The syntax of the regular expression is the standard one used with tools like grep. Note that this is different from the syntax used by shells, so for instance foo* matches all functions that include an fo followed by zero or more os. There is an implicit .* leading and trailing the regular expression you supply, so to match only functions that begin with foo, use ^foo.

Related

Using commas inside BOOST_CHECK_EXCEPTION macro

I'm working on a project that used BOOST_CHECK_EXCEPTION in unit tests. The first argument is a code block. It works well when the code under test has no commas. Once the code gets a comma that is not inside parentheses (e.g. constructor call with braces and multiple arguments), BOOST_CHECK_EXCEPTION stops working. The preprocessor treats the comma as an argument separator. The preprocessor is aware of parentheses, but not of braces.
So the code blocks that contain unparenthesized commas are defined as a lambdas outside BOOST_CHECK_EXCEPTION. That works, but I'm looking for a solution that keeps BOOST_CHECK_EXCEPTION invocations more uniform. After all, commas can appear and disappear from the expressions as the code is being developed.
First of all, just delaying comma expansion after BOOST_CHECK_EXCEPTION expansion doesn't work. The implementation of BOOST_CHECK_EXCEPTION (BOOST_CHECK_THROW_IMPL) would still reject the extra arguments. It means BOOST_PP_COMMA is not going to help.
One approach I considered is having a CODE_WRAPPER macro that would take the code block and wrap it into code that includes parentheses. Those parentheses need to survive all preprocessor expansion. for and while use parentheses about code, but I was unable to put code blocks inside them. Likewise, I could not get a code block inside a function call. They all expect an expression.
One approach that works is a statement expression. It is a GNU extension, so it limits the code to gcc and clang, which is undesirable.
Boost documentation recommends do {...} while(0), but it doesn't fix the issue with commas. https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/utf_reference/testing_tool_ref/assertion_boost_level_exception.html
Now I'm thinking of wrapping BOOST_CHECK_EXCEPTION inside a macro that would define a lambda transparently for the caller. And I'm surprised that I don't see much help online. I feel I'm missing something obvious.
Is there any easy way to use BOOST_CHECK_EXCEPTION with code blocks that include unparenthesized commas?

Regex: How to override global case sensitive modifier when I cannot delete it?

I have the following regex:
/I_CAN_MODIFY_ONLY_THIS/i
I cannot delete i global modifier. The only thing I can do is put something in place of I_CAN_MODIFY_ONLY_THIS. Is there a way to override global case insensitiveness?
Something like this apparently exists: (?i)caseless(?-i)cased(?i)caseless, but I cannot make it work. source
Edit:
Apparently inline mode modifiers does not work in the regex engine I need to use here
These are called "inline mode modifiers"
If you've tried, and it didn't work then sadly I think the simple answer is no.
There are different flavors/engines/implementations, and some support this and others don't. So it all depends how is the regex being run.
Some support it just at the start, overriding any listed outside, while others support placing in the middle of the regex.
On the same site you linked to, they provide a comparison of Flavors - from here I quickly compiled this list:
Inline Mode Modifier Support
Start or middle: Python
Just at start: JGsoft, .NET, Java, Perl, PCRE, PCRE2, PHP, Delphi, R, XRegExp, Ruby, Boost (ECMA), Tcl ARE
Not at all: Javascript, VBScript, std::Regex, POSIX BRE, GNU BRE, GNU ERE, Oracle, XML, XPath
http://www.regular-expressions.info/refmodifiers.html
Yes, you can override the global case in-sensitiveness by using the inline case-sensitive flag (?-i). So, the regex for this would be
(?-i)i_can_modify_only_this
see demo / explanation

Remove exception specifications from C++ code with sed

I want to automatically remove deprecated exception specifications from my c++ code and try to use sed for this task.
Exception specification format is throw following with list of exceptions (words) between parenthesis so I wrote this sed:
sed -r 's,throw\s*[(].*[)],,g' foo.cpp
It works for oneline specifications but does not work for multiline one's.
It seems like dot does not match newlines althougth according to documentation it have to: https://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html
I tried this workaround but it does not work either (actually it does not even work for oneline specifications):
sed -r 's,throw\s*[(][\s\S]*[)],,g'
How to make it work properly?
EDITED:
example of exception spec:
void foo() throw (std::runtime_error); //oneline
void bar() throw (std::runtime_error,
std::logic_error); //multiline
Many text editors (for example jEdit) support multi-file regex search & replace.
However, there is no syntactic distinction between a throw specification and a throw expression throwing a parenthesized variable. The two are mostly distinguished primarily by not appearing in the same syntactic context. You could also distinguish them by resolving the name. But that won't work to distinguish the throw expression throw(foo()), which throws a default-constructed object of type foo, and the throw specification throw(foo()), which makes the absurd but technically valid claim that the annotated function may throw an exception of type "function that takes no arguments and returns a foo".
If you want a reliable way of stripping exception specifications, the best way would be to write a Clang Tidy check.
There is a clang-tidy check for this already.
I got it to replace the throw specifications from our source with noexcept(false) with this commandline
clang-tidy --fix --checks=-*,modernize-use-noexcept foo.cpp -- -I /my/include/path
Compiler options such as include paths and defines need to go after the -- . For further documentation see
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-noexcept.html

Is it possible to create wrong Regular expression in ActionScript/Flex which will cause runtime error?

Is it possible to create wrong Regular expression in ActionScript/Flex which will cause runtime error? I've tried so many weird regexpes in Flex and Flex never complained! How do I know If my regexp valid?
In theory, according to the ActionScript 3.0 SyntaxError documentation, when a regular expression cannot be parsed a SyntaxError is generated at runtime that you can detect in a try/catch block.
In practice, I've never actually seen the RegExp class exhibit this behavior.
I don't have ActionScript/Flex, so I can't test this. Since you haven't given any examples, I don't know what you think is a "weird" regex. What happens if you try one of these:
/(?<=x*)foo/
(ECMAScript regexes don't support lookbehind)
/foo([/
(missing closing parentheses/brackets)
/foo)]/
(missing opening parentheses/brackets)
/foo(?)/
(Syntax error)
/foo\1/
(invalid backreference)
If your end goal is to determine whether a particular regular expression is valid or not then I'm not sure trying to intentionally generate runtime errors is the best way to accomplish that.
Instead I would recommend testing your patterns against known inputs and make sure they behave as intended. You can use a tool like this to test:
RegExr

Regular expression to match (C) function calls

Does anyone have a regular expression for matching function calls in C programs ?
Since C isn't a regular language and C function calls can contain arbitrary argument expressions, I fear the answer to your question is “no.”
After a bit more searching I decided to let the compiler do the hard work.
Get the compiler to produce a Register Transfer Language (RTL) file using the -dr options of gcc.
The produced RTL file has the suffix .rtl or .expand.
This file is far easier to parse as the functions calls are already identified.
I doubt you can find a regex that matches all (and only) the function calls in some source code. But maybe you could use a tool like Understand, or your IDE, to browse your code.