title: GDB breakpoint not stopping program (Breakpoint in Bullet Physics library)
body: <p>I'm currently debugging a C/C++ program I wrote that uses Bullet Physics.  I'm working on Ubuntu 14.04.3, using g++ 4.8.4, valgrind 3.10.1, and Bullet Physics 2.82.</p>
  
  <p>My compiling command (for debugging) is:</p>
  
  <pre><code>   g++ -fno-inline -O0 -g -Wall -Wl,-rpath=./more_libs/lib,--enable-new-dtags -std=gnu++11 -I../bullet-2.82-r2704/Demos/OpenGL/ -I./more_libs/include/ -I../bullet-2.82-r2704/src/ ./main.cpp -L../bullet-2.82-r2704/Glut/ -L./more_libs/lib/ -L./more_libs/mesa -L../bullet-build/Demos/OpenGL/ -L../more_libs/lib/x86_64-linux-gnu -L../bullet-build/src/BulletDynamics/ -L../bullet-build/src/BulletCollision/ -L../bullet-build/src/LinearMath/ -lOpenGLSupport -lGL -lGLU -lglut -lBulletDynamics -lBulletCollision -lLinearMath -lXi -lXxf86vm -lX11 -o ./app
  </code></pre>
  
  <p>(The difference between debugging and normal is the -O0 and -fno-inline options.  I'm adding library paths because I need this program to be portable to a cluster I don't have super-user privileges on.)</p>
  
  <p>Using Valgrind, I have found a ton of similar Uninitialized Value errors that look like this:</p>
  
  <pre><code>    Conditional jump or move depends on uninitialised value(s)
      at 0x4608C1: btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject**, int, btPersistentManifold**, int, btTypedConstraint**, int, btContactSolverInfo const&amp;, btIDebugDraw*) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x4591FC: btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject**, int, btPersistentManifold**, int, btTypedConstraint**, int, btContactSolverInfo const&amp;, btIDebugDraw*, btDispatcher*) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x46A3FF: btDiscreteDynamicsWorld::solveConstraints(btContactSolverInfo&amp;) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x467584: btDiscreteDynamicsWorld::internalSingleStepSimulation(float) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x465459: btDiscreteDynamicsWorld::stepSimulation(float, int, float) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x4088F4: NoiseWorld::clientMoveAndDisplay() (NoiseWorld.cpp:288)
      by 0x409A28: main (main.cpp:46)
      Uninitialised value was created by a heap allocation
      at 0x4C2ABBD: malloc (vg_replace_malloc.c:296)
      by 0x4EE043: btAlignedAllocDefault(unsigned long, int) (in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)
      by 0x40BC09: btHingeConstraint::operator new(unsigned long) (btHingeConstraint.h:103)
      by 0x40CF73: NoiseWorld::CreateHinge(int, int, int, float, float, float, float, float, float, float, float, bool) (NoiseWorld.h:332)
      by 0x40807C: NoiseWorld::initPhysics() (NoiseWorld.cpp:193)
      by 0x4099F4: main (main.cpp:41)
  </code></pre>
  
  <p>I've tried to look what's going on at solveGroupCacheFriendlySetup(), but when I set a breakpoint there and run GDB, the program doesn't stop---it just runs to completion.  I've set the breakpoint by function and by memory (which is constant across valgrind checks), but none of them are getting found/used.</p>
  
  <p>So, here's the question: How can I look at what's going on in solveGroupCacheFriendlySetup() during the run of program?  From there, I think I'll be able to figure out what was left uninitialized.</p>
  
  <p>Sorry in advance if this is a simple question, but I haven't been able to find the answer for the past two days.  I'm a novice programmer and I've taken on a big project, so I'm guessing there's something simple I'm doing wrong, but I don't know exactly to what ask at this point.</p>
  
  <p><strong>EDIT:</strong>
  Here is the function I need to look at while running, as per πάντα ῥεῖ's suggestion.  The online documentation for this function can be found here: <a href="http://bulletphysics.org/Bullet/BulletFull/classbtSequentialImpulseConstraintSolver.html" rel="nofollow">http://bulletphysics.org/Bullet/BulletFull/classbtSequentialImpulseConstraintSolver.html</a></p>
  
  <p>Note: This portion of the code was not written by me, and I'm not 100% what it does.  I'm pretty sure the error lies elsewhere; that I'm not setting up the physics-simulator environment well enough.</p>
  
  <p>Also, I do not know what the valgrind message "(in /home/josh/Documents/projects/evodevo_model/noise/EvoDevo-Modeling/evodevo/c++/app)" means in terms of trying to add a breakpoint that GDB can find when running the program.</p>
  
  <pre><code>btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo&amp; infoGlobal,btIDebugDraw* debugDrawer)
  {
      m_fixedBodyId = -1;
      BT_PROFILE("solveGroupCacheFriendlySetup");
      (void)debugDrawer;
  
      m_maxOverrideNumSolverIterations = 0;
  
  #ifdef BT_ADDITIONAL_DEBUG
       //make sure that dynamic bodies exist for all (enabled) constraints
      for (int i=0;i&lt;numConstraints;i++)
      {
          btTypedConstraint* constraint = constraints[i];
          if (constraint-&gt;isEnabled())
          {
              if (!constraint-&gt;getRigidBodyA().isStaticOrKinematicObject())
              {
                  bool found=false;
                  for (int b=0;b&lt;numBodies;b++)
                  {
  
                      if (&amp;constraint-&gt;getRigidBodyA()==bodies[b])
                      {
                          found = true;
                          break;
                      }
                  }
                  btAssert(found);
              }
              if (!constraint-&gt;getRigidBodyB().isStaticOrKinematicObject())
              {
                  bool found=false;
                  for (int b=0;b&lt;numBodies;b++)
                  {
                      if (&amp;constraint-&gt;getRigidBodyB()==bodies[b])
                      {
                          found = true;
                          break;
                      }
                  }
                  btAssert(found);
              }
          }
      }
      //make sure that dynamic bodies exist for all contact manifolds
      for (int i=0;i&lt;numManifolds;i++)
      {
          if (!manifoldPtr[i]-&gt;getBody0()-&gt;isStaticOrKinematicObject())
          {
              bool found=false;
              for (int b=0;b&lt;numBodies;b++)
              {
  
                  if (manifoldPtr[i]-&gt;getBody0()==bodies[b])
                  {
                      found = true;
                      break;
                  }
              }
              btAssert(found);
          }
          if (!manifoldPtr[i]-&gt;getBody1()-&gt;isStaticOrKinematicObject())
          {
              bool found=false;
              for (int b=0;b&lt;numBodies;b++)
              {
                  if (manifoldPtr[i]-&gt;getBody1()==bodies[b])
                  {
                      found = true;
                      break;
                  }
              }
              btAssert(found);
          }
      }
  #endif //BT_ADDITIONAL_DEBUG
  
  
      for (int i = 0; i &lt; numBodies; i++)
      {
          bodies[i]-&gt;setCompanionId(-1);
      }
  
  
      m_tmpSolverBodyPool.reserve(numBodies+1);
      m_tmpSolverBodyPool.resize(0);
  
      //btSolverBody&amp; fixedBody = m_tmpSolverBodyPool.expand();
      //initSolverBody(&amp;fixedBody,0);
  
      //convert all bodies
  
      for (int i=0;i&lt;numBodies;i++)
      {
          int bodyId = getOrInitSolverBody(*bodies[i],infoGlobal.m_timeStep);
  
          btRigidBody* body = btRigidBody::upcast(bodies[i]);
          if (body &amp;&amp; body-&gt;getInvMass())
          {
              btSolverBody&amp; solverBody = m_tmpSolverBodyPool[bodyId];
              btVector3 gyroForce (0,0,0);
              if (body-&gt;getFlags()&amp;BT_ENABLE_GYROPSCOPIC_FORCE)
              {
                  gyroForce = body-&gt;computeGyroscopicForce(infoGlobal.m_maxGyroscopicForce);
                  solverBody.m_externalTorqueImpulse -= gyroForce*body-&gt;getInvInertiaTensorWorld()*infoGlobal.m_timeStep;
              }
          }
      }
  
      if (1)
      {
          int j;
          for (j=0;j&lt;numConstraints;j++)
          {
              btTypedConstraint* constraint = constraints[j];
              constraint-&gt;buildJacobian();
              constraint-&gt;internalSetAppliedImpulse(0.0f);
          }
      }
  
      //btRigidBody* rb0=0,*rb1=0;
  
      //if (1)
      {
          {
  
              int totalNumRows = 0;
              int i;
  
              m_tmpConstraintSizesPool.resizeNoInitialize(numConstraints);
              //calculate the total number of contraint rows
              for (i=0;i&lt;numConstraints;i++)
              {
                  btTypedConstraint::btConstraintInfo1&amp; info1 = m_tmpConstraintSizesPool[i];
                  btJointFeedback* fb = constraints[i]-&gt;getJointFeedback();
                  if (fb)
                  {
                      fb-&gt;m_appliedForceBodyA.setZero();
                      fb-&gt;m_appliedTorqueBodyA.setZero();
                      fb-&gt;m_appliedForceBodyB.setZero();
                      fb-&gt;m_appliedTorqueBodyB.setZero();
                  }
  
                  if (constraints[i]-&gt;isEnabled())
                  {
                  }
                  if (constraints[i]-&gt;isEnabled())
                  {
                      constraints[i]-&gt;getInfo1(&amp;info1);
                  } else
                  {
                      info1.m_numConstraintRows = 0;
                      info1.nub = 0;
                  }
                  totalNumRows += info1.m_numConstraintRows;
              }
              m_tmpSolverNonContactConstraintPool.resizeNoInitialize(totalNumRows);
  
  
              ///setup the btSolverConstraints
              int currentRow = 0;
  
              for (i=0;i&lt;numConstraints;i++)
              {
                  const btTypedConstraint::btConstraintInfo1&amp; info1 = m_tmpConstraintSizesPool[i];
  
                  if (info1.m_numConstraintRows)
                  {
                      btAssert(currentRow&lt;totalNumRows);
  
                      btSolverConstraint* currentConstraintRow = &amp;m_tmpSolverNonContactConstraintPool[currentRow];
                      btTypedConstraint* constraint = constraints[i];
                      btRigidBody&amp; rbA = constraint-&gt;getRigidBodyA();
                      btRigidBody&amp; rbB = constraint-&gt;getRigidBodyB();
  
                      int solverBodyIdA = getOrInitSolverBody(rbA,infoGlobal.m_timeStep);
                      int solverBodyIdB = getOrInitSolverBody(rbB,infoGlobal.m_timeStep);
  
                      btSolverBody* bodyAPtr = &amp;m_tmpSolverBodyPool[solverBodyIdA];
                      btSolverBody* bodyBPtr = &amp;m_tmpSolverBodyPool[solverBodyIdB];
  
  
  
  
                      int overrideNumSolverIterations = constraint-&gt;getOverrideNumSolverIterations() &gt; 0 ? constraint-&gt;getOverrideNumSolverIterations() : infoGlobal.m_numIterations;
                      if (overrideNumSolverIterations&gt;m_maxOverrideNumSolverIterations)
                          m_maxOverrideNumSolverIterations = overrideNumSolverIterations;
  
  
                      int j;
                      for ( j=0;j&lt;info1.m_numConstraintRows;j++)
                      {
                          memset(&amp;currentConstraintRow[j],0,sizeof(btSolverConstraint));
                          currentConstraintRow[j].m_lowerLimit = -SIMD_INFINITY;
                          currentConstraintRow[j].m_upperLimit = SIMD_INFINITY;
                          currentConstraintRow[j].m_appliedImpulse = 0.f;
                          currentConstraintRow[j].m_appliedPushImpulse = 0.f;
                          currentConstraintRow[j].m_solverBodyIdA = solverBodyIdA;
                          currentConstraintRow[j].m_solverBodyIdB = solverBodyIdB;
                          currentConstraintRow[j].m_overrideNumSolverIterations = overrideNumSolverIterations;
                      }
  
                      bodyAPtr-&gt;internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f);
                      bodyAPtr-&gt;internalGetDeltaAngularVelocity().setValue(0.f,0.f,0.f);
                      bodyAPtr-&gt;internalGetPushVelocity().setValue(0.f,0.f,0.f);
                      bodyAPtr-&gt;internalGetTurnVelocity().setValue(0.f,0.f,0.f);
                      bodyBPtr-&gt;internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f);
                      bodyBPtr-&gt;internalGetDeltaAngularVelocity().setValue(0.f,0.f,0.f);
                      bodyBPtr-&gt;internalGetPushVelocity().setValue(0.f,0.f,0.f);
                      bodyBPtr-&gt;internalGetTurnVelocity().setValue(0.f,0.f,0.f);
  
  
                      btTypedConstraint::btConstraintInfo2 info2;
                      info2.fps = 1.f/infoGlobal.m_timeStep;
                      info2.erp = infoGlobal.m_erp;
                      info2.m_J1linearAxis = currentConstraintRow-&gt;m_contactNormal1;
                      info2.m_J1angularAxis = currentConstraintRow-&gt;m_relpos1CrossNormal;
                      info2.m_J2linearAxis = currentConstraintRow-&gt;m_contactNormal2;
                      info2.m_J2angularAxis = currentConstraintRow-&gt;m_relpos2CrossNormal;
                      info2.rowskip = sizeof(btSolverConstraint)/sizeof(btScalar);//check this
                      ///the size of btSolverConstraint needs be a multiple of btScalar
                      btAssert(info2.rowskip*sizeof(btScalar)== sizeof(btSolverConstraint));
                      info2.m_constraintError = &amp;currentConstraintRow-&gt;m_rhs;
                      currentConstraintRow-&gt;m_cfm = infoGlobal.m_globalCfm;
                      info2.m_damping = infoGlobal.m_damping;
                      info2.cfm = &amp;currentConstraintRow-&gt;m_cfm;
                      info2.m_lowerLimit = &amp;currentConstraintRow-&gt;m_lowerLimit;
                      info2.m_upperLimit = &amp;currentConstraintRow-&gt;m_upperLimit;
                      info2.m_numIterations = infoGlobal.m_numIterations;
                      constraints[i]-&gt;getInfo2(&amp;info2);
  
                      ///finalize the constraint setup
                      for ( j=0;j&lt;info1.m_numConstraintRows;j++)
                      {
                          btSolverConstraint&amp; solverConstraint = currentConstraintRow[j];
  
                          if (solverConstraint.m_upperLimit&gt;=constraints[i]-&gt;getBreakingImpulseThreshold())
                          {
                              solverConstraint.m_upperLimit = constraints[i]-&gt;getBreakingImpulseThreshold();
                          }
  
                          if (solverConstraint.m_lowerLimit&lt;=-constraints[i]-&gt;getBreakingImpulseThreshold())
                          {
                              solverConstraint.m_lowerLimit = -constraints[i]-&gt;getBreakingImpulseThreshold();
                          }
  
                          solverConstraint.m_originalContactPoint = constraint;
  
                          {
                              const btVector3&amp; ftorqueAxis1 = solverConstraint.m_relpos1CrossNormal;
                              solverConstraint.m_angularComponentA = constraint-&gt;getRigidBodyA().getInvInertiaTensorWorld()*ftorqueAxis1*constraint-&gt;getRigidBodyA().getAngularFactor();
                          }
                          {
                              const btVector3&amp; ftorqueAxis2 = solverConstraint.m_relpos2CrossNormal;
                              solverConstraint.m_angularComponentB = constraint-&gt;getRigidBodyB().getInvInertiaTensorWorld()*ftorqueAxis2*constraint-&gt;getRigidBodyB().getAngularFactor();
                          }
  
                          {
                              btVector3 iMJlA = solverConstraint.m_contactNormal1*rbA.getInvMass();
                              btVector3 iMJaA = rbA.getInvInertiaTensorWorld()*solverConstraint.m_relpos1CrossNormal;
                              btVector3 iMJlB = solverConstraint.m_contactNormal2*rbB.getInvMass();//sign of normal?
                              btVector3 iMJaB = rbB.getInvInertiaTensorWorld()*solverConstraint.m_relpos2CrossNormal;
  
                              btScalar sum = iMJlA.dot(solverConstraint.m_contactNormal1);
                              sum += iMJaA.dot(solverConstraint.m_relpos1CrossNormal);
                              sum += iMJlB.dot(solverConstraint.m_contactNormal2);
                              sum += iMJaB.dot(solverConstraint.m_relpos2CrossNormal);
                              btScalar fsum = btFabs(sum);
                              btAssert(fsum &gt; SIMD_EPSILON);
                              solverConstraint.m_jacDiagABInv = fsum&gt;SIMD_EPSILON?btScalar(1.)/sum : 0.f;
                          }
  
  
  
                          {
                              btScalar rel_vel;
                              btVector3 externalForceImpulseA = bodyAPtr-&gt;m_originalBody ? bodyAPtr-&gt;m_externalForceImpulse : btVector3(0,0,0);
                              btVector3 externalTorqueImpulseA = bodyAPtr-&gt;m_originalBody ? bodyAPtr-&gt;m_externalTorqueImpulse : btVector3(0,0,0);
  
                              btVector3 externalForceImpulseB = bodyBPtr-&gt;m_originalBody ? bodyBPtr-&gt;m_externalForceImpulse : btVector3(0,0,0);
                              btVector3 externalTorqueImpulseB = bodyBPtr-&gt;m_originalBody ?bodyBPtr-&gt;m_externalTorqueImpulse : btVector3(0,0,0);
  
                              btScalar vel1Dotn = solverConstraint.m_contactNormal1.dot(rbA.getLinearVelocity()+externalForceImpulseA) 
                                                  + solverConstraint.m_relpos1CrossNormal.dot(rbA.getAngularVelocity()+externalTorqueImpulseA);
  
                              btScalar vel2Dotn = solverConstraint.m_contactNormal2.dot(rbB.getLinearVelocity()+externalForceImpulseB) 
                                                                  + solverConstraint.m_relpos2CrossNormal.dot(rbB.getAngularVelocity()+externalTorqueImpulseB);
  
                              rel_vel = vel1Dotn+vel2Dotn;
                              btScalar restitution = 0.f;
                              btScalar positionalError = solverConstraint.m_rhs;//already filled in by getConstraintInfo2
                              btScalar    velocityError = restitution - rel_vel * info2.m_damping;
                              btScalar    penetrationImpulse = positionalError*solverConstraint.m_jacDiagABInv;
                              btScalar    velocityImpulse = velocityError *solverConstraint.m_jacDiagABInv;
                              solverConstraint.m_rhs = penetrationImpulse+velocityImpulse;
                              solverConstraint.m_appliedImpulse = 0.f;
  
  
                          }
                      }
                  }
                  currentRow+=m_tmpConstraintSizesPool[i].m_numConstraintRows;
              }
          }
  
          convertContacts(manifoldPtr,numManifolds,infoGlobal);
  
      }
  
  //  btContactSolverInfo info = infoGlobal;
  
  
      int numNonContactPool = m_tmpSolverNonContactConstraintPool.size();
      int numConstraintPool = m_tmpSolverContactConstraintPool.size();
      int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size();
  
      ///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
      m_orderNonContactConstraintPool.resizeNoInitialize(numNonContactPool);
      if ((infoGlobal.m_solverMode &amp; SOLVER_USE_2_FRICTION_DIRECTIONS))
          m_orderTmpConstraintPool.resizeNoInitialize(numConstraintPool*2);
      else
          m_orderTmpConstraintPool.resizeNoInitialize(numConstraintPool);
  
      m_orderFrictionConstraintPool.resizeNoInitialize(numFrictionPool);
      {
          int i;
          for (i=0;i&lt;numNonContactPool;i++)
          {
              m_orderNonContactConstraintPool[i] = i;
          }
          for (i=0;i&lt;numConstraintPool;i++)
          {
              m_orderTmpConstraintPool[i] = i;
          }
          for (i=0;i&lt;numFrictionPool;i++)
          {
              m_orderFrictionConstraintPool[i] = i;
          }
      }
  
      return 0.f;
  
  }
  </code></pre>