Please have a try at the following snippet (this is still cocos2dx v2 but you can easily upgrade it to v3).
void YourSprite::draw() {
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);
kmGLPushMatrix();
CCRect bb = boundingBox();
CCPoint vertices[4] = {
CCPoint( bb.origin.x, bb.origin.y ),
CCPoint( bb.origin.x, bb.origin.y + bb.size.height ),
CCPoint( bb.origin.x + bb.size.width, bb.origin.y + bb.size.height ),
CCPoint( bb.origin.x + bb.size.width, bb.origin.y)
};
ccDrawColor4B(255, 255, 0, 255);
glLineWidth(2);
ccDrawPoly(vertices, 4, true);
kmGLPopMatrix(); }
Also check out CCDrawNode and drawPolygon which has better performance than DrawPrimitive.
PS: note that you should reset the line width to its previous state.
float oldWidth = .0f;
glGetFloatv(GL_LINE_WIDTH, &oldWidth);
/// Set new line width
glLineWidth(mLineWidth);
....
/// Reset previous line width
glLineWidth(oldWidth);