1

I'm trying to grep for suppressions containing a certain library in a Valgrind log which is a couple of million lines long with PCREGrep.

I can get each suppression individually using pcregrep -M "{\n([^}]+\n)+}" which produces individual entries like this:

{
   <insert_a_suppression_name_here>
   Memcheck:ReallocZero
   fun:realloc
   obj:/usr/lib/libnvidia-glcore.so.535.54.03
   obj:/usr/lib/libGLX_nvidia.so.535.54.03
   obj:/usr/lib/libGLX_nvidia.so.535.54.03
   obj:/usr/lib/libGLX_nvidia.so.535.54.03
}

What I wanted to do was find all entries which reference nvidia, so I tried {\n([^}]+\n)+.+nvidia.+\n([^}]+\n)+}. This causes PCREGrep to produce output which looks like this:

pcregrep: pcre_exec() gave error -8 while matching text that starts:

{
   <insert_a_suppression_name_here>
   Memcheck:Value8
   obj:/usr/lib/libnvidia-glcore.so.535.54.03
   obj:/usr/lib/libnvidia-glcore.so.535.54.03
   obj:/usr/lib/libnvidia-glcore.so.535.54.03
   ob

as well as the terminating message

pcregrep: Too many errors - abandoned.
pcregrep: Error -8, -21 or -27 means that a resource limit was exceeded.
pcregrep: Check your regex for nested unlimited loops.

How can I format this regex in a way that doesn't cause this issue? Or if the issue is inherently present in my scenario, how can I increase whatever limit is being hit?

Emily-TTG
  • 531
  • 3
  • 18
  • Try a pattern of `\{[^}]+?nvidia[^}]+?\}`, which should need much much much less backtracking. – Shawn Jul 05 '23 at 17:02
  • @Shawn yeah that worked - thank you! How come? – Emily-TTG Jul 05 '23 at 17:06
  • Nested +'s like you were using give exponential behavior. I suggest the book [Mastering Regular Expressions](https://www.oreilly.com/library/view/mastering-regular-expressions/0596528124/) – Shawn Jul 05 '23 at 17:09
  • (`\{(?:nvidia|[^}])+?\}` might be even better) – Shawn Jul 05 '23 at 17:12

0 Answers0